- // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout
- s = jQuery.extend({
- global: true,
- ifModified: false,
- type: "GET",
- timeout: jQuery.timeout,
- complete: null,
- success: null,
- error: null,
- dataType: null,
- url: null,
- data: null,
- contentType: "application/x-www-form-urlencoded",
- processData: true,
- async: true,
- beforeSend: null
- }, s);
-
- // if data available
- if ( s.data ) {
- // convert data if not already a string
- if (s.processData && typeof s.data != 'string')
- s.data = jQuery.param(s.data);
- // append data to url for get requests
- if( s.type.toLowerCase() == "get" )
- // "?" + data or "&" + data (in case there are already params)
- s.url += ((s.url.indexOf("?") > -1) ? "&" : "?") + s.data;
+ var jsonp, jsre = /=(\?|%3F)/g, status, data;
+
+ // Extend the settings, but re-extend 's' so that it can be
+ // checked again later (in the test suite, specifically)
+ s = jQuery.extend(true, s, jQuery.extend(true, {}, jQuery.ajaxSettings, s));
+
+ // convert data if not already a string
+ if ( s.data && s.processData && typeof s.data != "string" )
+ s.data = jQuery.param(s.data);
+
+ // Break the data into one single string
+ var q = s.url.indexOf("?");
+ if ( q > -1 ) {
+ s.data = (s.data ? s.data + "&" : "") + s.url.slice(q + 1);
+ s.url = s.url.slice(0, q);
+ }
+
+ // Handle JSONP Parameter Callbacks
+ if ( s.dataType == "jsonp" ) {
+ if ( !s.data || !s.data.match(jsre) )
+ s.data = (s.data ? s.data + "&" : "") + (s.jsonp || "callback") + "=?";
+ s.dataType = "json";
+ }
+
+ // Build temporary JSONP function
+ if ( s.dataType == "json" && s.data && s.data.match(jsre) ) {
+ jsonp = "jsonp" + jsc++;
+ s.data = s.data.replace(jsre, "=" + jsonp);
+
+ // We need to make sure
+ // that a JSONP style response is executed properly
+ s.dataType = "script";
+
+ // Handle JSONP-style loading
+ window[ jsonp ] = function(tmp){
+ data = tmp;
+ success();
+ // Garbage collect
+ window[ jsonp ] = undefined;
+ try{ delete window[ jsonp ]; } catch(e){}
+ };
+ }
+
+ if ( s.dataType == "script" && s.cache == null )
+ s.cache = false;
+
+ if ( s.cache === false && s.type.toLowerCase() == "get" )
+ s.data = (s.data ? s.data + "&" : "") + "_=" + (new Date()).getTime();
+
+ // If data is available, append data to url for get requests
+ if ( s.data && s.type.toLowerCase() == "get" ) {
+ s.url += "?" + s.data;
+
+ // IE likes to send both get and post data, prevent this
+ s.data = null;