I am experiencing a weird issue with PUT and POST ajax CORS requests in jQuery when not passing any data parameters.
So I enabled CORS on my server by setting the headers. Everything works fine when I do for example:
$.ajax({
url: "http://127.0.0.1/R/index.html",
type: "PUT",
data: {foo:"bar"}
});
However, when I do the same request without setting the data parameter, firefox returns without ever posting the ajax:
$.ajax({
url: "http://127.0.0.1/R/index.html",
type: "PUT"
});
Note that this only happens for the POST and PUT methods, when a full url is specified in the request, and no http data parameters are specified. It also happens when the url is on the same domain as the page itself (hence no CORS is required). It does not happen if I just specify a path in the url, instead of a full url.
Any clues how I can do a POST/PUT without passing any parameters (my server won’t accept ‘fake’ parameters).
I am pretty sure by now it is a bug in jQuery when it calls the ‘multipart/form-data’ encoder in cross-domain ajax requests for when there is no data posted.
It can be avoided by using something like this: