Skip to content

Commit

Permalink
Did some cleaning up of ajax.js and fixed a bug from commit [6457].
Browse files Browse the repository at this point in the history
  • Loading branch information
jeresig committed Jul 19, 2009
1 parent 81985c7 commit fa2d663
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/ajax.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -177,20 +177,23 @@ jQuery.extend({
// checked again later (in the test suite, specifically) // checked again later (in the test suite, specifically)
s = jQuery.extend(true, s, jQuery.extend(true, {}, jQuery.ajaxSettings, s)); s = jQuery.extend(true, s, jQuery.extend(true, {}, jQuery.ajaxSettings, s));


var jsonp, jsre = /=\?(&|$)/g, status, data, var jsonp, jsre = /=\?(&|$)/, status, data,
type = s.type.toUpperCase(); type = s.type.toUpperCase();


// convert data if not already a string // convert data if not already a string
if ( s.data && s.processData && typeof s.data !== "string" ) if ( s.data && s.processData && typeof s.data !== "string" ) {
s.data = jQuery.param(s.data); s.data = jQuery.param(s.data);
}


// Handle JSONP Parameter Callbacks // Handle JSONP Parameter Callbacks
if ( s.dataType == "jsonp" ) { if ( s.dataType == "jsonp" ) {
if ( type == "GET" ) { if ( type == "GET" ) {
if ( !jsre.test( s.url ) ) if ( !jsre.test( s.url ) ) {
s.url += (/\?/.test( s.url ) ? "&" : "?") + (s.jsonp || "callback") + "=?"; s.url += (/\?/.test( s.url ) ? "&" : "?") + (s.jsonp || "callback") + "=?";
} else if ( !s.data || !jsre.test(s.data) ) }
} else if ( !s.data || !jsre.test(s.data) ) {
s.data = (s.data ? s.data + "&" : "") + (s.jsonp || "callback") + "=?"; s.data = (s.data ? s.data + "&" : "") + (s.jsonp || "callback") + "=?";
}
s.dataType = "json"; s.dataType = "json";
} }


Expand All @@ -199,8 +202,10 @@ jQuery.extend({
jsonp = "jsonp" + jsc++; jsonp = "jsonp" + jsc++;


// Replace the =? sequence both in the query string and the data // Replace the =? sequence both in the query string and the data
if ( s.data ) if ( s.data ) {
s.data = (s.data + "").replace(jsre, "=" + jsonp + "$1"); s.data = (s.data + "").replace(jsre, "=" + jsonp + "$1");
}

s.url = s.url.replace(jsre, "=" + jsonp + "$1"); s.url = s.url.replace(jsre, "=" + jsonp + "$1");


// We need to make sure // We need to make sure
Expand Down

0 comments on commit fa2d663

Please sign in to comment.