-1

CODEIGNITER

I'm trying to delete an instance in the db using an ajax delete request. I'm trying to pass data with the id of the instance I want to delete.

In my javascript when i use 'type:POST' in my ajax call the code works correctly and the data is deleted but when i use type:DELETEit doesn't work.

JAVASCRIPT AJAX CALL

$(".complete").click(function(){
    var title = this.id;
    //console.log(title);
     $.ajax({
       url: '/ajax-requestDel',
       type: 'DELETE',    <!-- when i use type:'POST" the code works
       data: {title: title},
       error: function() {
          alert('Something is wrong');

       },
       success: function(data) {
           console.log(data);
       }

    });
});

CONTROLLER CODE

    public function ajaxRequestDelete(){
       $data = $this->input->post('title');
       return $this->db->delete('todo', array('title'=>$data));
    }

When debugging i have found that the variable $data is empty but when using a post call it has the desired value.

How do i repeat the same behavior using delete. Thanks.

Athira
  • 1,177
  • 3
  • 13
  • 35
TrollSafe
  • 27
  • 5

1 Answers1

1

The data will arrive at the php input stream php://input for a DELETE request.

You should use $this->input->input_stream('title'); as per the manual

See also: get a PHP delete variable

andrew
  • 9,313
  • 7
  • 30
  • 61