8

In my client app—written in javascript and jQuery—I have a function where I'm doing $.ajax request with the DELETE method to my server.

The code is something like this:

    this.delete_one = function(id){
    console.log(id);
    $.ajax({
        url: sitesCtrl.url,
        type: "delete",
        dataType: 'json',
        data: {"id": id},
        success: function(data){
            if (data.success){
                $("sitesList").remove("#" + id + "\"");
            }
            else{
                console.log(data.message);
            }
        },
        error: function(){
            console.log("internal error");
        }
    })
};

The problem is that the server gets the request with no parameter "id"! Just a simple DELETE (according to firebug). with PUT, POST, or GET it works great.

Gabriel Hurley
  • 39,690
  • 13
  • 62
  • 88
Anton Koval'
  • 4,863
  • 5
  • 31
  • 44

1 Answers1

7

Interesting. I can't find anything in the RFC but it stands to reason that there is no way to pass parameters using the DELETE methods - only in GET and POST, so either JQuery or the browser correctly filter out the parameters. This is just a guess, though, maybe somebody who knows this stuff by heart can make a more profound statement.

Anyway, if this is how JQuery works right now, I think your workaround will have to be putting the ID into the URL, and mod_rewrite it out.

Before you do that, try whether you can't trick the browser in passing it through by adding the parameter to the URL: sitesCtrl.url+'?ID='+id

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • Pekka, thnx for answer. Some time before, i worked with project on cherrypy + ExtJS, and DELETE requests from ExtJS to CP ran quite fast and without any additional problems :) – Anton Koval' Feb 15 '10 at 21:50
  • "*I can't find anything in the RFC [...]*": you must have missed the bit that defines [`Request-URI`](http://tools.ietf.org/html/rfc2616#section-5.1.2). The [URI includes everything including query parameters](http://tools.ietf.org/html/rfc2616#section-3.2) (even the fragments are part of the URI, but they're not to be sent in requests). – Bruno Aug 15 '13 at 17:30
  • @Bruno indeed. So adding the parameters into the URL should work. I do recommend trying that in the final paragraph of the answer - but if you have a working example, feel free to post that as an answer and I'll be happy to remove mine (when I can - accepted answers can't be deleted) – Pekka Aug 15 '13 at 18:45