+ // Main method
+ // (s is used internally)
+ ajax: function( url , options , s ) {
+
+ // Handle varargs
+ if ( arguments.length === 1 ) {
+ options = url;
+ url = options ? options.url : undefined;
+ }
+
+ // Force options to be an object
+ options = options || {};
+
+ // Get the url if provided separately
+ options.url = url || options.url;
+
+ // Create the final options object
+ s = jQuery.extend( true , {} , jQuery.ajaxSettings , options );
+
+ // We force the original context
+ // (plain objects used as context get extended)
+ s.context = options.context;
+
+ var // jQuery lists
+ jQuery_lastModified = jQuery.lastModified,
+ jQuery_etag = jQuery.etag,
+ // Callbacks contexts
+ callbackContext = s.context || s,
+ globalEventContext = s.context ? jQuery( s.context ) : jQuery.event,
+ // Deferreds
+ deferred = jQuery.Deferred(),
+ completeDeferred = jQuery._Deferred(),
+ // Headers (they are sent all at once)
+ requestHeaders = {},
+ // Response headers
+ responseHeadersString,
+ responseHeaders,
+ // transport
+ transport,
+ // timeout handle
+ timeoutTimer,
+ // The jXHR state
+ state = 0,
+ // Loop variable
+ i,
+ // Fake xhr
+ jXHR = {
+
+ readyState: 0,
+
+ // Caches the header
+ setRequestHeader: function(name,value) {
+ if ( state === 0 ) {
+ requestHeaders[ name.toLowerCase() ] = value;
+ }
+ return this;
+ },
+
+ // Raw string
+ getAllResponseHeaders: function() {
+ return state === 2 ? responseHeadersString : null;
+ },
+
+ // Builds headers hashtable if needed
+ // (match is used internally)
+ getResponseHeader: function( key , match ) {
+
+ if ( state !== 2 ) {
+ return null;
+ }
+
+ if ( responseHeaders === undefined ) {
+
+ responseHeaders = {};
+
+ if ( typeof responseHeadersString === "string" ) {
+
+ while( ( match = rheaders.exec( responseHeadersString ) ) ) {
+ responseHeaders[ match[ 1 ].toLowerCase() ] = match[ 2 ];
+ }
+ }
+ }
+ return responseHeaders[ key.toLowerCase() ];
+ },
+
+ // Cancel the request
+ abort: function( statusText ) {
+ if ( transport && state !== 2 ) {
+ transport.abort( statusText || "abort" );
+ done( 0 , statusText );
+ }
+ return this;
+ }
+ };