+ // Clear timeout if it exists
+ if ( timeoutTimer ) {
+ clearTimeout(timeoutTimer);
+ }
+
+ var // Reference url
+ url = s.url,
+ // and ifModified status
+ ifModified = s.ifModified,
+
+ // Is it a success?
+ isSuccess = 0,
+ // Stored success
+ success,
+ // Stored error
+ error = statusText;
+
+ // If not timeout, force a jQuery-compliant status text
+ if ( statusText != "timeout" ) {
+ statusText = ( status >= 200 && status < 300 ) ?
+ "success" :
+ ( status === 304 ? "notmodified" : "error" );
+ }
+
+ // If successful, handle type chaining
+ if ( statusText === "success" || statusText === "notmodified" ) {
+
+ // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
+ if ( s.ifModified ) {
+
+ var lastModified = jXHR.getResponseHeader("Last-Modified"),
+ etag = jXHR.getResponseHeader("Etag");
+
+ if (lastModified) {
+ jQuery_lastModified[ s.url ] = lastModified;
+ }
+ if (etag) {
+ jQuery_etag[ s.url ] = etag;
+ }
+ }
+
+ if ( s.ifModified && statusText === "notmodified" ) {
+
+ success = null;
+ isSuccess = 1;
+
+ } else {
+ // Chain data conversions and determine the final value
+ // (if an exception is thrown in the process, it'll be notified as an error)
+ try {
+
+ var i,
+ current,
+ prev,
+ checker,
+ conv1,
+ conv2,
+ oneConv,
+ convertion,
+ dataTypes = s.dataTypes,
+ dataConverters = s.dataConverters,
+ responses = {
+ "xml": "XML",
+ "text": "Text"
+ };
+
+ for( i = 0 ; i < dataTypes.length ; i++ ) {
+
+ current = dataTypes[ i ];
+
+ if ( responses[ current ] ) {
+ jXHR[ "response" + responses[ current ] ] = response;
+ responses[ current ] = 0;
+ }
+
+ if ( i ) {
+
+ if ( prev !== "*" && current !== "*" && prev !== current ) {
+
+ oneConv = conv1 =
+ dataConverters[ ( conversion = prev + " " + current ) ] ||
+ dataConverters[ "* " + current ];
+
+ if ( oneConv !== true ) {
+
+ if ( ! oneConv && prev !== "text" && current !== "text" ) {
+ conv1 = dataConverters[ prev + " text" ] || dataConverters[ "* text" ];
+ conv2 = dataConverters[ "text " + current ];
+ }
+
+ if ( oneConv || conv1 && conv2 ) {
+ response = oneConv ? conv1( response ) : conv2( conv1( response ) );
+ } else {
+ throw "no " + conversion;
+ }
+ }
+ }
+ } else if ( s.dataFilter ) {
+
+ response = s.dataFilter( response );
+ dataTypes = s.dataTypes;
+ }
+
+ prev = current;
+ }
+
+ // We have a real success
+ success = response;
+ isSuccess = 1;
+
+ } catch(e) {
+
+ statusText = "parsererror";
+ error = "" + e;
+
+ }
+ }
+
+ } else { // if not success, mark it as an error
+
+ error = error || statusText;
+ }
+
+ // Set data for the fake xhr object
+ jXHR.status = status;
+ jXHR.statusText = statusText;
+
+ // Success/Error
+ if ( isSuccess ) {
+ deferred.fire( callbackContext , [ success , statusText , jXHR ] );
+ } else {
+ deferred.fireReject( callbackContext , [ jXHR , statusText , error ] );
+ }
+
+ if ( s.global ) {
+ globalEventContext.trigger( "ajax" + ( isSuccess ? "Success" : "Error" ) ,
+ [ jXHR , s , isSuccess ? success : error ] );
+ }
+
+ // Complete
+ completeDeferred.fire( callbackContext, [ jXHR , statusText ] );
+
+ if ( s.global ) {
+ globalEventContext.trigger( "ajaxComplete" , [ jXHR , s] );
+ // Handle the global AJAX counter
+ if ( ! --jQuery.active ) {
+ jQuery.event.trigger( "ajaxStop" );
+ }
+ }
+ }
+
+ // Attach deferreds
+ jXHR.success = jXHR.then = deferred.then;
+ jXHR.error = jXHR.fail = deferred.fail;
+ jXHR.complete = completeDeferred.then;