Side navigation
#11224 closed bug (wontfix)
Opened January 25, 2012 05:18PM UTC
Closed February 04, 2012 04:14PM UTC
$.ajaxSetup data object does not merge when $.ajax call passes a string.
Reported by: | mike@ruhl.in | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.7.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
I'm trying to use $.ajaxSetup to add a default parameter to every ajax request on my page, but it's being made more difficult by this bug combined with some bad code a contractor wrote.
If I make any ajax calls using jquery, and I define my parameters as a urlencoded string instead of a javascript object, they will ignore the defaults set by $.ajaxSetup. consider the following example code:
$(function(){
$.ajaxSetup({'data': {'secret': 'token'}});
$.get("/echo/json/", "param=stuff");
$.get("/echo/json/", {"param": "stuff"});
});
The first .get call requests /echo/json/?param=stuff whereas the second requests /echo/json/?param=stuff&secret=token.
Would be kind of nice if this would parse the query stringified version into an object, then do the merge.
Attachments (0)
Change History (3)
Changed January 25, 2012 07:37PM UTC by comment:1
Changed February 04, 2012 03:12PM UTC by comment:2
status: | new → open |
---|
I am not sure whether this is a case we should handle, but if not we should document it.
Changed February 04, 2012 04:14PM UTC by comment:3
resolution: | → wontfix |
---|---|
status: | open → closed |
We definitely shouldn't handle this. Cost is prohibitive. Don't encode your parameters OR deserialize them before giving them to $.ajax.
I added the following hack to my local copy of jQuery. (started with version 1.4.2, line 4982.)
this works in my use case, but probably breaks others.