]> source.dussan.org Git - jquery.git/commitdiff
Reformats logic for early abort in beforeSend to limit block imbrication.
authorjaubourg <j@ubourg.net>
Fri, 4 Feb 2011 21:29:10 +0000 (22:29 +0100)
committerjaubourg <j@ubourg.net>
Fri, 4 Feb 2011 21:29:10 +0000 (22:29 +0100)
src/ajax.js

index e56db83b5272658f223cc647f2dfc23face6e8cd..4830e3df8925345e9df36decb360353e4b5af629 100644 (file)
@@ -667,50 +667,49 @@ jQuery.extend({
                // Allow custom headers/mimetypes and early abort
                if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
                                // Abort if not done already
-                               done( 0, "abort" );
-                               // Return false
-                               jqXHR = false;
+                               jqXHR.abort();
+                               return false;
 
-               } else {
+               }
 
-                       // Install callbacks on deferreds
-                       for ( i in { success: 1, error: 1, complete: 1 } ) {
-                               jqXHR[ i ]( s[ i ] );
-                       }
+               // Install callbacks on deferreds
+               for ( i in { success: 1, error: 1, complete: 1 } ) {
+                       jqXHR[ i ]( s[ i ] );
+               }
 
-                       // Get transport
-                       transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
+               // Get transport
+               transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
 
-                       // If no transport, we auto-abort
-                       if ( !transport ) {
-                               done( -1, "No Transport" );
-                       } else {
-                               // Set state as sending
-                               state = jqXHR.readyState = 1;
-                               // Send global event
-                               if ( fireGlobals ) {
-                                       globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
-                               }
-                               // Timeout
-                               if ( s.async && s.timeout > 0 ) {
-                                       timeoutTimer = setTimeout( function(){
-                                               jqXHR.abort( "timeout" );
-                                       }, s.timeout );
-                               }
+               // If no transport, we auto-abort
+               if ( !transport ) {
+                       done( -1, "No Transport" );
+               } else {
+                       // Set state as sending
+                       state = jqXHR.readyState = 1;
+                       // Send global event
+                       if ( fireGlobals ) {
+                               globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
+                       }
+                       // Timeout
+                       if ( s.async && s.timeout > 0 ) {
+                               timeoutTimer = setTimeout( function(){
+                                       jqXHR.abort( "timeout" );
+                               }, s.timeout );
+                       }
 
-                               try {
-                                       transport.send( requestHeaders, done );
-                               } catch (e) {
-                                       // Propagate exception as error if not done
-                                       if ( status < 2 ) {
-                                               done( -1, e );
-                                       // Simply rethrow otherwise
-                                       } else {
-                                               jQuery.error( e );
-                                       }
+                       try {
+                               transport.send( requestHeaders, done );
+                       } catch (e) {
+                               // Propagate exception as error if not done
+                               if ( status < 2 ) {
+                                       done( -1, e );
+                               // Simply rethrow otherwise
+                               } else {
+                                       jQuery.error( e );
                                }
                        }
                }
+
                return jqXHR;
        },