DELETE cannot retrive parameters.
The DELETE method cannot retrive the parameters sent into a JSON string. POST, PUT Works fine but DELETE doesn't.
Content-Type : application/json
{ "id":"27" }
public function index_delete(){
$response = new stdClass();
$id = $this->delete('id');
$this->Employee_model->id = $id;
$succeed = $this->Employee_model->delete_entry() > 0;
$response->succeed = $succeed;
$response->id = $id;
$this->response($response);
}
$id = $this->delete('id'); returns FALSE.
Hi,
I've had this problem too, so I edited the _parse_delete() method
protected function _parse_delete() { // Set up out DELETE variables (which shouldn't really exist, but sssh!) if (stripos($this->input->server('CONTENT_TYPE'), "application/xml") === FALSE) { $this->_delete_args = (array)json_decode(file_get_contents("php://input")); } else { $this->_delete_args = $this->format->_from_xml(file_get_contents("php://input")); } }
now I can send xml and json to a delete method
@arjanvdwal1992 thanks for the fix
*** edit ***
my problem was, that I didn't send the data as JSON and that was why the _parse_delete() couldn't "find" the data. now that I'm passing JSON data, everything is working fine.
@arjanvdwal1992 Thanks for the fix! Just ran into the same problem.
@pkyeck Did you not need this fix in the end? I couldn't get it to work otherwise.
@Hebime yes, I did. but I also had to explicitly tell my ajax request to be json formatted:
$.ajax({
beforeSend: function(xhr){
xhr.setRequestHeader("Content-Type", "application/json");
},
url: "/data/block/2",
type: "DELETE",
dataType: "json",
processData: false,
data: JSON.stringify(data),
success: function(data) {
console.log(data);
}
});
this is what I found with my commit saying that it fixed the problem ;)
@pkyeck Ahh ok! Thanks for clarifying! :)