Using jQuery 1.2.1, if I have:
$.ajax({
type: "POST",
url: "test.html",
dataType: "json",
data: {query: queryString},
});
When queryString starts with a ? it will get converted to
jsonp1231234124...
This is clearly happening because of the code at line 2226 of the full
release version:
// Build temporary JSONP function
if ( s.dataType == "json" && (s.data &&
s.data.match(jsre)
s.url.match(jsre)) ) {
jsonp = "jsonp" + jsc++;
// Replace the =? sequence both in the query
string and the data
if ( s.data )
s.data = s.data.replace(jsre, "=" +
jsonp);
s.url = s.url.replace(jsre, "=" + jsonp);
...
But I see no way to prevent that from happening.
Now... one might suggest that I should avoid a leading ? in my option names. But I am taking them from input boxes and ? is a valid thing for a user to type. Unfortunately there seems to be no good way to escape the string to prevent this behavior (without teaching the called code how to unescape it).
Also, the docs don't mention that the =? escaping happens to a json
dataType... I see it for jsonp.
Is this behavior intentional? If so, there should be a way to
suppress it or at a way for the calling code to escape the values to
cause a leading ? to be passed to the server.
This behavior is present in the latest svn version of the code too:
http://dev.jquery.com/browser/trunk/jquery/src/ajax.js
But not in releases preceeding 1.2.
Attachments
Change History
Download in other formats:
|