Does the jQuery $.ajaxSetup method not respect the data field in the options hash when $.post or $.get is called?
For example, I might have this code:
$.ajaxSetup({ data: { persist: true } });
Then, to send a POST request, I would call this:
$.post("/create/something", { name: "foo" });
I was expecting the actual POST data to look like this:
{
persist: true,
name: "foo"
}
but the only data sent by $.post is { name: "foo" }. Is there any way to get the expected behavior? I’m using jQuery 1.4.1.
$.ajaxSetup()sets defaults for your ajax requests. Any options you set in the request method will override these defaults, not merge them. You’re actually overridingwith
This no longer appears to be the case — a ticket on the jQuery tracker suggests that this was added in a version update and jQuery now merges the objects instead of replacing the default (thanks @Quincy).