diff options
author | jaubourg <j@ubourg.net> | 2014-01-25 08:20:18 +0100 |
---|---|---|
committer | jaubourg <j@ubourg.net> | 2014-01-29 14:18:58 +0100 |
commit | 01c360f96390ff16edfe65ef3b34e167087ef645 (patch) | |
tree | 2419904105326230d25b97dcececc92a134f2f8d /src | |
parent | 53e31f478e1d88d056aa52f6575d200fe3dcf047 (diff) | |
download | jquery-01c360f96390ff16edfe65ef3b34e167087ef645.tar.gz jquery-01c360f96390ff16edfe65ef3b34e167087ef645.zip |
Ajax: Protect against exceptions thrown synchronously by xhr.send
When xhr.send throws an exception synchronously, the onerror handler may have
been called already which, unchecked, makes the exception bubble up outside of
jQuery.ajax.
We now catch the exception pre-emptively and only rethrow if we know it hasn't
already been notified through the onerror handler.
Fixes #14683
Diffstat (limited to 'src')
-rw-r--r-- | src/ajax/xhr.js | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/ajax/xhr.js b/src/ajax/xhr.js index 55d526a41..bdeeee3f8 100644 --- a/src/ajax/xhr.js +++ b/src/ajax/xhr.js @@ -112,10 +112,15 @@ jQuery.ajaxTransport(function( options ) { // Create the abort callback callback = xhrCallbacks[ id ] = callback("abort"); - // 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 ); + try { + // Do send the request (this may raise an exception) + xhr.send( options.hasContent && options.data || null ); + } catch ( e ) { + // #14683: Only rethrow if this hasn't been notified as an error yet + if ( callback ) { + throw e; + } + } }, abort: function() { |