From: jaubourg Date: Fri, 4 Feb 2011 21:29:10 +0000 (+0100) Subject: Reformats logic for early abort in beforeSend to limit block imbrication. X-Git-Tag: 1.5.1rc1~55 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8f8961de90453274ac194479272a8dfa99ffab17;p=jquery.git Reformats logic for early abort in beforeSend to limit block imbrication. --- diff --git a/src/ajax.js b/src/ajax.js index e56db83b5..4830e3df8 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -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; },