question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

$.ajax Sends `data` property in DELETE body instead of query string

See original GitHub issue

Description

The $.ajax functionality in regards to the data property is not compliant to the RFC spec for HTTP DELETE standards and causes issues. Currently we are running an api behind a Google Compute L7 Load Balancer and are getting 400 error codes when sending DELETE requests using data.

Current docs for $.ajax:

data Type: PlainObject or String or Array Data to be sent to the server. It is converted to a query string, if not already a string. It’s appended to the url for GET-requests. See processData option to prevent this automatic processing. Object must be Key/Value pairs. If value is an Array, jQuery serializes multiple values with same key based on the value of the traditional setting (described below).

Why not send data in body??

The HTTP Spec states the following…

“A payload within a DELETE request message has no defined semantics; sending a payload body on a DELETE request might cause some existing implementations to reject the request.”

site: https://tools.ietf.org/html/rfc7231#section-4.3.5

Who cares what the spec says??

Apparently Google does. Here’s a response from a cloud support specialist regarding the matter…

DELETE requests with a payload are rejected at the Google frontend service. As stated at [1] “A payload within a DELETE request message has no defined semantics; sending a payload body on a DELETE request might cause some existing implementations to reject the request.” Given that the load balancer does not allow a DELETE request with a body, the workarounds you have are to either use the same URL without a body or use a handler where you can POST the same body and delete the specific topic ID.

I would very much appreciate if you could fix the $.ajax functionality to work correctly per the standards defined here, or a more recent version of the specification. I believe the GET method works in this way and if the DELETE method could be changed to work the same as GET, that would be perfect.

I’m a long time user and fan of jQuery and I look forward to continued use. Thank you for taking a few minutes to review my request.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mgolcommented, Dec 13, 2016

@bs-thomas Please read https://bugs.jquery.com/ticket/7285 and the ticket that @dmethvin linked to. We are following the spec as it doesn’t disallow sending body on DELETE. This is different to e.g. HEAD requests which explicitly disallow it and we don’t send body in HEAD requests because of that.

If you want us to forbid sending body in DELETE requests, first convince standard bodies to explicitly disallow it in the spec. Then we’re surely follow.

1reaction
dmethvincommented, Aug 10, 2016

That’s the point made in the ticket though. You can already serialize params to the URL. It’s not any longer or more difficult to code, and it’s clear to anyone reading it later that you’re adding them to the URL–because you’re adding them to the URL:

$.ajax({
    url: 'http://example.com?' + $.param({foo: 'bar'})
});

We could certainly add something like queryData that was explicit about where the data went, but that would require new code plus new documentation, and new complex rules (does queryData override data or is it in addition? What about GET requests?). Plus it would confuse people using jQuery 1.x and 2.x where it won’t exist, and those people will end up using the code above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pass data in the ajax DELETE request other than ...
The DELETE method requests that the origin server delete the resource identified by the Request-URI. So you need to pass the data in...
Read more >
11586 ($.ajax DELETE request not passing data parameters)
I managed to get a mock up written by manually creating am XMLHttpRequest, FireBug was showing the data being sent in the body...
Read more >
jQuery ajax() Method - TutorialsTeacher
This tutorial shows how to send ajax request using jQuery ajax() method. The jQuery ajax() method provides core functionality of Ajax in jQuery....
Read more >
AJAX Introduction - W3Schools
AJAX is a developer's dream, because you can: Update a web page without reloading the page; Request data from a server - after...
Read more >
How to Use Fetch to Make AJAX Calls in JavaScript
Fetch is an interface for making an AJAX request in JavaScript. ... PATCH / DELETE / PUT you can use the method property...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found