function done( status, nativeStatusText, responses, headers ) {

      // Called once
      if ( state === 2 ) {
        return;
      }

      // State is "done" now
      state = 2;

      // Clear timeout if it exists
      if ( timeoutTimer ) {
        clearTimeout( timeoutTimer );
      }

      // Dereference transport for early garbage collection
      // (no matter how long the jqXHR object will be used)
      transport = undefined;

      // Cache response headers
      responseHeadersString = headers || "";

      // Set readyState
      jqXHR.readyState = status > 0 ? 4 : 0;

      var isSuccess,
        success,
        error,
        statusText = nativeStatusText,
        response = responses ? ajaxHandleResponses( s, jqXHR, responses ) : undefined,
        lastModified,
        etag;

      // If successful, handle type chaining
      if ( status >= 200 && status < 300 || status === 304 ) {

        // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
        if ( s.ifModified ) {

          if ( ( lastModified = jqXHR.getResponseHeader( "Last-Modified" ) ) ) {
            jQuery.lastModified[ ifModifiedKey ] = lastModified;
          }
          if ( ( etag = jqXHR.getResponseHeader( "Etag" ) ) ) {
            jQuery.etag[ ifModifiedKey ] = etag;
          }
        }

        // If not modified
        if ( status === 304 ) {

          statusText = "notmodified";
          isSuccess = true;

        // If we have data
        } else {

          try {
            success = ajaxConvert( s, response );
            statusText = "success";
            isSuccess = true;
          } catch(e) {
            // We have a parsererror
            statusText = "parsererror";
            error = e;
          }
        }
      } else {
        // We extract error from statusText
        // then normalize statusText and status for non-aborts
        error = statusText;
        if( !statusText || status ) {
          statusText = "error";
          if ( status < 0 ) {
            status = 0;
          }
        }
      }

      // Set data for the fake xhr object
      jqXHR.status = status;
      jqXHR.statusText = "" + ( nativeStatusText || statusText );

      // Success/Error
      if ( isSuccess ) {
        deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
      } else {
        deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
      }

      // Status-dependent callbacks
      jqXHR.statusCode( statusCode );
      statusCode = undefined;

      if ( fireGlobals ) {
        globalEventContext.trigger( "ajax" + ( isSuccess ? "Success" : "Error" ),
            [ jqXHR, s, isSuccess ? success : error ] );
      }

      // Complete
      completeDeferred.resolveWith( callbackContext, [ jqXHR, statusText ] );

      if ( fireGlobals ) {
        globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
        // Handle the global AJAX counter
        if ( !( --jQuery.active ) ) {
          jQuery.event.trigger( "ajaxStop" );
        }
      }
    }
// at the end of the function (which would be more logical and readable)
at the end of the function (which would be more logical and readable)
at the end of the function ( which would be more logical and readable )
function done( status, nativeStatusText, responses, headers ) {
      if ( state === 2 ) {
        return;
      }
      state = 2;
      if ( timeoutTimer ) {
        clearTimeout( timeoutTimer );
      }
      transport = undefined;
      responseHeadersString = headers || "";
      jqXHR.readyState = status > 0 ? 4 : 0;
      var isSuccess,
        success,
        error,
        statusText = nativeStatusText,
        response = responses ? ajaxHandleResponses( s, jqXHR, responses ) : undefined,
        lastModified,
        etag;
      if ( status >= 200 && status < 300 || status === 304 ) {
        if ( s.ifModified ) {
          if ( ( lastModified = jqXHR.getResponseHeader( "Last-Modified" ) ) ) {
            jQuery.lastModified[ ifModifiedKey ] = lastModified;
          }
          if ( ( etag = jqXHR.getResponseHeader( "Etag" ) ) ) {
            jQuery.etag[ ifModifiedKey ] = etag;
          }
        }
        if ( status === 304 ) {
          statusText = "notmodified";
          isSuccess = true;
        } else {
          try {
            success = ajaxConvert( s, response );
            statusText = "success";
            isSuccess = true;
          } catch(e) {
            statusText = "parsererror";
            error = e;
          }
        }
      } else {
        error = statusText;
        if( !statusText || status ) {
          statusText = "error";
          if ( status < 0 ) {
            status = 0;
          }
        }
      }
      jqXHR.status = status;
      jqXHR.statusText = "" + ( nativeStatusText || statusText );
      if ( isSuccess ) {
        deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
      } else {
        deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
      }
      jqXHR.statusCode( statusCode );
      statusCode = undefined;
      if ( fireGlobals ) {
        globalEventContext.trigger( "ajax" + ( isSuccess ? "Success" : "Error" ),
            [ jqXHR, s, isSuccess ? success : error ] );
      }
      completeDeferred.resolveWith( callbackContext, [ jqXHR, statusText ] );
      if ( fireGlobals ) {
        globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
        if ( !( --jQuery.active ) ) {
          jQuery.event.trigger( "ajaxStop" );
        }
      }
    }
function done ( status , nativeStatusText , responses , headers ) { if ( state === 2 ) { return ; } state = 2 ; if ( timeoutTimer ) { clearTimeout ( timeoutTimer ) ; } transport = undefined ; responseHeadersString = headers || "" ; jqXHR . readyState = status > 0 ? 4 : 0 ; var isSuccess , success , error , statusText = nativeStatusText , response = responses ? ajaxHandleResponses ( s , jqXHR , responses ) : undefined , lastModified , etag ; if ( status >= 200 && status < 300 || status === 304 ) { if ( s . ifModified ) { if ( ( lastModified = jqXHR . getResponseHeader ( "Last-Modified" ) ) ) { jQuery . lastModified [ ifModifiedKey ] = lastModified ; } if ( ( etag = jqXHR . getResponseHeader ( "Etag" ) ) ) { jQuery . etag [ ifModifiedKey ] = etag ; } } if ( status === 304 ) { statusText = "notmodified" ; isSuccess = true ; } else { try { success = ajaxConvert ( s , response ) ; statusText = "success" ; isSuccess = true ; } catch ( e ) { statusText = "parsererror" ; error = e ; } } } else { error = statusText ; if ( ! statusText || status ) { statusText = "error" ; if ( status < 0 ) { status = 0 ; } } } jqXHR . status = status ; jqXHR . statusText = "" + ( nativeStatusText || statusText ) ; if ( isSuccess ) { deferred . resolveWith ( callbackContext , [ success , statusText , jqXHR ] ) ; } else { deferred . rejectWith ( callbackContext , [ jqXHR , statusText , error ] ) ; } jqXHR . statusCode ( statusCode ) ; statusCode = undefined ; if ( fireGlobals ) { globalEventContext . trigger ( "ajax" + ( isSuccess ? "Success" : "Error" ) , [ jqXHR , s , isSuccess ? success : error ] ) ; } completeDeferred . resolveWith ( callbackContext , [ jqXHR , statusText ] ) ; if ( fireGlobals ) { globalEventContext . trigger ( "ajaxComplete" , [ jqXHR , s ] ) ; if ( ! ( -- jQuery . active ) ) { jQuery . event . trigger ( "ajaxStop" ) ; } } }
at the end of the function (which would be more logical and readable)
at the end of the function ( which would be more logical and readable )
// Called once // State is "done" now // Clear timeout if it exists // Dereference transport for early garbage collection // (no matter how long the jqXHR object will be used) // Cache response headers // Set readyState // If successful, handle type chaining // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode. // If not modified // If we have data // We have a parsererror // We extract error from statusText // then normalize statusText and status for non-aborts // Set data for the fake xhr object // Success/Error // Status-dependent callbacks // Complete // Handle the global AJAX counter