views:

40

answers:

2

I just updated from jQuery 1.3.2 to 1.4.3, and I'm seeing some new behavior when making AJAX DELETE requests. For some reason, the data being passed in my data parameter is not being sent to the server. For example:

$.ajax({
    url: '/example',
    data: {id: 12},
    type: 'DELETE'
});

Ends up sending a DELETE request to /example with no additional data. However, this type of call passes the parameters just fine:

$.ajax({
    url: '/example?id=12',
    type: 'DELETE'
});

Has anyone else seen similar behavior? Is there a reason this is no longer working (i.e.: is it by design, or is it a bug)? Any suggestions on how to get it working?

Also, in case anyone is wondering why I don't simply want to pass the parameters as part of the URL string, it's because I'm ultimately attempting to use the $.ajaxSetup callback, providing some general parameters there (namely the authenticity_token parameter used to protect against forgery in Rails). This all worked fine prior to trying jQuery 1.4.3.

A: 

Could this be related to the traditional parameter? It usually relates to complex types and not a simple id parameter but worth checking if this is not the case:

$.ajax({
    url: '/example',
    data: { id: someValue },
    traditional: true,
    type: 'DELETE'
});
Darin Dimitrov
Doesn't look to be the issue here, thanks though!
Matt Huggins
+3  A: 

jQuery will only append parameters to the querystring for GET requests only (and no body for DELETE requests), so this is intentional behavior in jQuery 1.4.3.

However, there is a change since then (commit here) to allow a body for DELETE requests in the 1.4.4 release.

Nick Craver
Thanks, Nick. Any suggestions on a workaround? Given your response, I attempted to update `settings.url` in the `$.ajaxSend()` callback such that I append the query string values there for DELETE requests; however, it looks like the returned value of `settings.url` isn't being captured for use in jQuery 1.4.3 as it is in 1.3.2. Any other thoughts on dealing with this, other than manually appending the same parameter to every single request everywhere in my code?
Matt Huggins
@Matt - I think 1.4.4 is due out very soon as a bugfix release, look at this commit an hour ago labeling it 1.4.4pre: http://github.com/jquery/jquery/commit/9b97599fa4d615a91d1605d9c664c50f576911ce I would say hang tight a few days, grab 1.4.4 final and you're all set. Here's a blog post on it: http://blog.jquery.com/2010/10/24/community-updates-2610/
Nick Craver
Unfortunately deadlines force me to deal with this now. I guess I'll update the calls inline for now, and refactor in a couple days when this becomes available. Thanks so much for your insight, you're always incredibly helpful on here!
Matt Huggins