Reformats logic for early abort in beforeSend to limit block imbrication.

This commit is contained in:
jaubourg 2011-02-04 22:29:10 +01:00
parent 03bad0a960
commit 8f8961de90

View File

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