I have the following code:
$.ajax({
method: "POST",
url: "/handler",
contentType: "application/json",
data: data_all,
})
.done(function(r) { ...stuff... })
.fail(function(r) { ...stuff... });
data_all
is a dictionary (e.g., {"a":1, "b":2}
). Running this code currently returns a 400 error (using django, in case relevant). If I make one change:
...
data: JSON.stringify(data_all),
...
It all works.
The thing is, that shouldn't be the case. The jQuery AJAX docs clearly states that the data
argument accepts strings, arrays, and PlainObjects. When in debugger mode (using Chrome dev tools), I have verified that data_all
is a PlainObject:
jQuery.isPlainObject(data_all) # returns "true"
I'm using jQuery 2.1.4, so this should be there. Any idea why this requires the stringify
function?