#6834 closed bug (wontfix)
$.ajax doesn't uri encode a string input automatically
Reported by: | xiaoyongaz | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | |
Component: | ajax | Version: | 1.4.2 |
Keywords: | ajax | Cc: | |
Blocked by: | Blocking: |
Description
when I pass "ab+cd" as input, it will become "ab cd" after deparam. when "ab+cd" is used in an object such as {a:"ab+cd"}, it will be encoded by calling encodeURIComponent(key)/(value). ajax should do the same for string input.
Attachments (2)
Change History (9)
comment:1 Changed 13 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 Changed 13 years ago by
Resolution: | invalid |
---|---|
Status: | closed → reopened |
add below js in a html file
var parms_str = "ab+ba"; var paramResult = $.param(parms_str, false); alert(paramResult); var deObj = $.deparam(paramResult, false); var deObj2 = $.deparam("ab ba", false); alert(deObj); alert(deObj2);
you can see alert deObj shows "ab ba" instead of "ab+ba"
Changed 13 years ago by
qunit test the show deparam change 'ab+ba' to 'ab ba'
Changed 13 years ago by
comment:3 Changed 13 years ago by
actuall this might be clearer, in ajax function, jQuery does
convert data if not already a string if ( s.data && s.processData && typeof s.data !== "string" ) {
s.data = jQuery.param( s.data, s.traditional );
}
so string input is not encoded. then we can see in the attached test, deparam will change 'ab+ba' to 'ab ba'.
comment:4 Changed 13 years ago by
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
I'm sorry but I don't understand your test case. jQuery does not have a $.deparam method and $.ajax isn't used in the test case although it is supposedly the component being reported. Is this a bug report intended for jQuery core?
comment:5 Changed 13 years ago by
Resolution: | invalid |
---|---|
Status: | closed → reopened |
The ajax isn't used because I need to setup a server to show it and it's hard to attach the whole server stack. You just need to look at the ajax function of the jQuery code below
if ( s.data && s.processData && typeof s.data !== "string" ) {
s.data = jQuery.param( s.data, s.traditional );
}
there, you don't encode string for ajax calls, but encode string in objects, which is inconsistent
comment:7 Changed 13 years ago by
Priority: | → undecided |
---|---|
Resolution: | → wontfix |
Status: | reopened → closed |
If you pass a string to the data option of $.ajax
, you are responsible for performing any necessary serialization/encoding of the string. jQuery will not do this for you; if it did, it would end up double-encoding data (or otherwise mangling non-application/x-www-form-urlencoded data).
Please reopen and attach a test case.