Permalink
Browse files

Ajax: Catch synchronous readystatechange events

Fixes gh-2673
Ref trac-14683
  • Loading branch information...
gibson042 committed Oct 23, 2015
1 parent c40b12a commit 0a6e1c4b191f177fce2dac5fd3a17b76f853fd26
Showing with 8 additions and 6 deletions.
  1. +8 −6 src/ajax/xhr.js
View
@@ -105,11 +105,6 @@ if ( xhrSupported ) {
}
}
- // Do send the request
- // This may raise an exception which is actually
- // handled in jQuery.ajax (so no try/catch here)
- xhr.send( ( options.hasContent && options.data ) || null );
-
// Listener
callback = function( _, isAbort ) {
var status, statusText, responses;
@@ -168,14 +163,21 @@ if ( xhrSupported ) {
}
};
+ // Do send the request
+ // `xhr.send` may raise an exception, but it will be
+ // handled in jQuery.ajax (so no try/catch here)
if ( !options.async ) {
- // if we're in sync mode we fire the callback
+ xhr.send( ( options.hasContent && options.data ) || null );
+
+ // If we're in sync mode we fire the callback
callback();
} else {
// Add to the list of active xhr callbacks
xhr.onreadystatechange = callback;
+
+ xhr.send( ( options.hasContent && options.data ) || null );
}
},

1 comment on commit 0a6e1c4

@markelog

This comment has been minimized.

Show comment
Hide comment
Member

markelog commented on 0a6e1c4 Oct 23, 2015

/cc @jaubourg

Please sign in to comment.