Skip to content

Commit 0a6e1c4

Browse files
committed
Ajax: Catch synchronous readystatechange events
Fixes gh-2673 Ref trac-14683
1 parent c40b12a commit 0a6e1c4

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/ajax/xhr.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,6 @@ if ( xhrSupported ) {
105105
}
106106
}
107107

108-
// Do send the request
109-
// This may raise an exception which is actually
110-
// handled in jQuery.ajax (so no try/catch here)
111-
xhr.send( ( options.hasContent && options.data ) || null );
112-
113108
// Listener
114109
callback = function( _, isAbort ) {
115110
var status, statusText, responses;
@@ -168,14 +163,21 @@ if ( xhrSupported ) {
168163
}
169164
};
170165

166+
// Do send the request
167+
// `xhr.send` may raise an exception, but it will be
168+
// handled in jQuery.ajax (so no try/catch here)
171169
if ( !options.async ) {
172170

173-
// if we're in sync mode we fire the callback
171+
xhr.send( ( options.hasContent && options.data ) || null );
172+
173+
// If we're in sync mode we fire the callback
174174
callback();
175175
} else {
176176

177177
// Add to the list of active xhr callbacks
178178
xhr.onreadystatechange = callback;
179+
180+
xhr.send( ( options.hasContent && options.data ) || null );
179181
}
180182
},
181183

0 commit comments

Comments
 (0)