]> source.dussan.org Git - jquery.git/commitdiff
Ajax: Catch synchronous readystatechange events
authorRichard Gibson <richard.gibson@gmail.com>
Fri, 23 Oct 2015 15:35:11 +0000 (11:35 -0400)
committerRichard Gibson <richard.gibson@gmail.com>
Fri, 23 Oct 2015 15:35:11 +0000 (11:35 -0400)
Fixes gh-2673
Ref trac-14683

src/ajax/xhr.js

index 313f24a04a041c6b482cb8888207f00d12f833ea..b62417138919c5e26eabd7c36d3d20fb361ee83f 100644 (file)
@@ -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 );
                                        }
                                },