mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Reformats logic for early abort in beforeSend to limit block imbrication.
This commit is contained in:
parent
03bad0a960
commit
8f8961de90
73
src/ajax.js
73
src/ajax.js
@ -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;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user