+ // Attach deferreds
+ deferred.promise( jXHR );
+ jXHR.success = jXHR.complete;
+ jXHR.error = jXHR.fail;
+ jXHR.complete = completeDeferred.complete;
+
+ // Remove hash character (#7531: and string promotion)
+ s.url = ( "" + s.url ).replace( rhash , "" );
+
+ // Uppercase the type
+ s.type = s.type.toUpperCase();
+
+ // Determine if request has content
+ s.hasContent = ! rnoContent.test( s.type );
+
+ // Extract dataTypes list
+ s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().split( /\s+/ );
+
+ // Determine if a cross-domain request is in order
+ var parts = rurl.exec( s.url.toLowerCase() ),
+ loc = location;
+ s.crossDomain = !!( parts && ( parts[ 1 ] && parts[ 1 ] != loc.protocol || parts[ 2 ] != loc.host ) );
+
+ // Convert data if not already a string
+ if ( s.data && s.processData && typeof s.data != "string" ) {
+ s.data = jQuery.param( s.data , s.traditional );
+ }
+
+ // Watch for a new set of requests
+ if ( s.global && jQuery.active++ === 0 ) {
+ jQuery.event.trigger( "ajaxStart" );
+ }
+
+ // Get transport
+ transport = jQuery.ajax.prefilter( s ).transport( s );
+
+ // If no transport, we auto-abort
+ if ( ! transport ) {
+
+ done( 0 , "transport not found" );
+ jXHR = false;
+
+ } else {
+
+ // More options handling for requests with no content
+ if ( ! s.hasContent ) {
+
+ // If data is available, append data to url
+ if ( s.data ) {
+ s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.data;
+ }
+
+ // Add anti-cache in url if needed
+ if ( s.cache === false ) {
+
+ var ts = jQuery.now(),
+ // try replacing _= if it is there
+ ret = s.url.replace( rts , "$1_=" + ts );
+
+ // if nothing was replaced, add timestamp to the end
+ s.url = ret + ( (ret == s.url ) ? ( rquery.test( s.url ) ? "&" : "?" ) + "_=" + ts : "");
+ }
+ }
+
+ // Set the correct header, if data is being sent
+ if ( ( s.data && s.hasContent ) || options.contentType ) {
+ requestHeaders[ "content-type" ] = s.contentType;
+ }
+
+ // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
+ if ( s.ifModified ) {
+ if ( jQuery_lastModified[ s.url ] ) {
+ requestHeaders[ "if-modified-since" ] = jQuery_lastModified[ s.url ];
+ }
+ if ( jQuery_etag[ s.url ] ) {
+ requestHeaders[ "if-none-match" ] = jQuery_etag[ s.url ];
+ }
+ }
+
+ // Set the Accepts header for the server, depending on the dataType
+ requestHeaders.accept = s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[ 0 ] ] ?
+ s.accepts[ s.dataTypes[ 0 ] ] + ( s.dataTypes[ 0 ] !== "*" ? ", */*; q=0.01" : "" ) :
+ s.accepts[ "*" ];
+
+ // Check for headers option
+ for ( i in s.headers ) {
+ requestHeaders[ i.toLowerCase() ] = s.headers[ i ];
+ }
+
+ // Allow custom headers/mimetypes and early abort
+ if ( s.beforeSend && ( s.beforeSend.call( callbackContext , jXHR , s ) === false || state === 2 ) ) {
+
+ // Abort if not done already
+ done( 0 , "abort" );
+ jXHR = false;
+
+ } else {
+
+ // Set state as sending
+ state = 1;
+ jXHR.readyState = 1;
+
+ // Install callbacks on deferreds
+ for ( i in { success:1, error:1, complete:1 } ) {
+ jXHR[ i ]( s[ i ] );
+ }
+
+ // Send global event
+ if ( s.global ) {
+ globalEventContext.trigger( "ajaxSend" , [ jXHR , s ] );
+ }
+
+ // Timeout
+ if ( s.async && s.timeout > 0 ) {
+ timeoutTimer = setTimeout(function(){
+ jXHR.abort( "timeout" );
+ }, s.timeout);
+ }
+
+ // Try to send
+ try {
+ transport.send(requestHeaders, done);
+ } catch (e) {
+ // Propagate exception as error if not done
+ if ( status === 1 ) {
+
+ done(0, "error", "" + e);
+ jXHR = false;
+
+ // Simply rethrow otherwise
+ } else {
+ jQuery.error(e);
+ }
+ }
+ }