Skip to content
Permalink
Browse files

Reformats logic for early abort in beforeSend to limit block imbricat…

…ion.
  • Loading branch information...
jaubourg committed Feb 4, 2011
1 parent 03bad0a commit 8f8961de90453274ac194479272a8dfa99ffab17
Showing with 35 additions and 36 deletions.
  1. +35 −36 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;
},

0 comments on commit 8f8961d

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.