Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$.ajax with DELETE loses parameters

Tags:

jquery

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.

like image 937
Anton Koval' Avatar asked Feb 15 '10 21:02

Anton Koval'


1 Answers

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

like image 162
Pekka Avatar answered Sep 23 '22 23:09

Pekka