aboutsummaryrefslogtreecommitdiffstats
path: root/src/ajax.js
diff options
context:
space:
mode:
authorjaubourg <j@ubourg.net>2011-02-04 22:29:10 +0100
committerjaubourg <j@ubourg.net>2011-02-04 22:29:10 +0100
commit8f8961de90453274ac194479272a8dfa99ffab17 (patch)
treeb4189b1de5e892c642f83fd0ee18e2a475db3331 /src/ajax.js
parent03bad0a9600f05e61a1464c55354d26fcd8f97a4 (diff)
downloadjquery-8f8961de90453274ac194479272a8dfa99ffab17.tar.gz
jquery-8f8961de90453274ac194479272a8dfa99ffab17.zip
Reformats logic for early abort in beforeSend to limit block imbrication.
Diffstat (limited to 'src/ajax.js')
-rw-r--r--src/ajax.js71
1 files changed, 35 insertions, 36 deletions
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;
},