$.ajax Sends `data` property in DELETE body instead of query string
See original GitHub issueDescription
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:
- Created 7 years ago
- Comments:6 (3 by maintainers)
@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.
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:
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 (doesqueryData
overridedata
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.