4

Does JQuery 1.8 or 1.7.2 support data parameters in a DELETE ajax request, e.g.

$.ajax({
    url: '/config/delete',
    type: 'DELETE',
    data: {id:'blah'}
}

If not, a workaround could be

$.ajax({
    url: '/config/delete?id=blah',
    type: 'DELETE'
}

My questions:

  1. I've seen people saying that they explicitly don't want to use the second approach, but why? Is there any security reason?

  2. If the first approach does not work and the second approach is bad, what is the alternative here? Sending a POST request with a method argument, e.g. data:{... method:'delete'}?

skyork
  • 7,113
  • 18
  • 63
  • 103
  • http://stackoverflow.com/questions/5894400/does-jquery-ajax-work-in-modern-browsers-with-put-and-delete – Ashirvad Sep 08 '12 at 04:11
  • @AshirvadSingh, thanks but the above question is different. I specifically want to know the body parameter part of a `DELETE` request, not its compatibility with browsers – skyork Sep 08 '12 at 15:16

1 Answers1

0

The DELETE HTTP request method has no body to carry some data.

So no matter which approach you use, the id=blah or {id:'blah'} will not be delivered.
This ain't due to jQuery version, but to the nature of the HTTP method itself.

The use of the DELETE method is to delete the accessed ressource.
The file /config/delete would not be executed, but deleted from the server.

Plus, this method isn't allowed in HTML forms... So I won't work via Ajax.

Louys Patrice Bessette
  • 33,375
  • 6
  • 36
  • 64