summaryrefslogtreecommitdiffstats
path: root/js/vendor/jquery/src/ajax/xhr.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/vendor/jquery/src/ajax/xhr.js')
-rw-r--r--js/vendor/jquery/src/ajax/xhr.js115
1 files changed, 73 insertions, 42 deletions
diff --git a/js/vendor/jquery/src/ajax/xhr.js b/js/vendor/jquery/src/ajax/xhr.js
index c2b43c921..db670ff15 100644
--- a/js/vendor/jquery/src/ajax/xhr.js
+++ b/js/vendor/jquery/src/ajax/xhr.js
@@ -1,4 +1,4 @@
-define([
+define( [
"../core",
"../var/support",
"../ajax"
@@ -6,47 +6,41 @@ define([
jQuery.ajaxSettings.xhr = function() {
try {
- return new XMLHttpRequest();
- } catch( e ) {}
+ return new window.XMLHttpRequest();
+ } catch ( e ) {}
};
-var xhrId = 0,
- xhrCallbacks = {},
- xhrSuccessStatus = {
- // file protocol always yields status code 0, assume 200
+var xhrSuccessStatus = {
+
+ // File protocol always yields status code 0, assume 200
0: 200,
+
// Support: IE9
// #1450: sometimes IE returns 1223 when it should be 204
1223: 204
},
xhrSupported = jQuery.ajaxSettings.xhr();
-// Support: IE9
-// Open requests must be manually aborted on unload (#5280)
-// See https://support.microsoft.com/kb/2856746 for more info
-if ( window.attachEvent ) {
- window.attachEvent( "onunload", function() {
- for ( var key in xhrCallbacks ) {
- xhrCallbacks[ key ]();
- }
- });
-}
-
support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
support.ajax = xhrSupported = !!xhrSupported;
-jQuery.ajaxTransport(function( options ) {
- var callback;
+jQuery.ajaxTransport( function( options ) {
+ var callback, errorCallback;
// Cross domain only allowed if supported through XMLHttpRequest
if ( support.cors || xhrSupported && !options.crossDomain ) {
return {
send: function( headers, complete ) {
var i,
- xhr = options.xhr(),
- id = ++xhrId;
+ xhr = options.xhr();
- xhr.open( options.type, options.url, options.async, options.username, options.password );
+ xhr.open(
+ options.type,
+ options.url,
+ options.async,
+ options.username,
+ options.password
+ );
// Apply custom fields if provided
if ( options.xhrFields ) {
@@ -65,8 +59,8 @@ jQuery.ajaxTransport(function( options ) {
// akin to a jigsaw puzzle, we simply never set it to be sure.
// (it can always be set on a per-request basis or even using ajaxSetup)
// For same-domain requests, won't change header if already provided.
- if ( !options.crossDomain && !headers["X-Requested-With"] ) {
- headers["X-Requested-With"] = "XMLHttpRequest";
+ if ( !options.crossDomain && !headers[ "X-Requested-With" ] ) {
+ headers[ "X-Requested-With" ] = "XMLHttpRequest";
}
// Set headers
@@ -78,27 +72,38 @@ jQuery.ajaxTransport(function( options ) {
callback = function( type ) {
return function() {
if ( callback ) {
- delete xhrCallbacks[ id ];
- callback = xhr.onload = xhr.onerror = null;
+ callback = errorCallback = xhr.onload =
+ xhr.onerror = xhr.onabort = xhr.onreadystatechange = null;
if ( type === "abort" ) {
xhr.abort();
} else if ( type === "error" ) {
- complete(
- // file: protocol always yields status 0; see #8605, #14207
- xhr.status,
- xhr.statusText
- );
+
+ // Support: IE9
+ // On a manual native abort, IE9 throws
+ // errors on any property access that is not readyState
+ if ( typeof xhr.status !== "number" ) {
+ complete( 0, "error" );
+ } else {
+ complete(
+
+ // File: protocol always yields status 0; see #8605, #14207
+ xhr.status,
+ xhr.statusText
+ );
+ }
} else {
complete(
xhrSuccessStatus[ xhr.status ] || xhr.status,
xhr.statusText,
- // Support: IE9
- // Accessing binary-data responseText throws an exception
- // (#11426)
- typeof xhr.responseText === "string" ? {
- text: xhr.responseText
- } : undefined,
+
+ // Support: IE9 only
+ // IE9 has no XHR2 but throws on binary (trac-11426)
+ // For XHR2 non-text, let the caller handle it (gh-2498)
+ ( xhr.responseType || "text" ) !== "text" ||
+ typeof xhr.responseText !== "string" ?
+ { binary: xhr.response } :
+ { text: xhr.responseText },
xhr.getAllResponseHeaders()
);
}
@@ -108,15 +113,41 @@ jQuery.ajaxTransport(function( options ) {
// Listen to events
xhr.onload = callback();
- xhr.onerror = callback("error");
+ errorCallback = xhr.onerror = callback( "error" );
+
+ // Support: IE9
+ // Use onreadystatechange to replace onabort
+ // to handle uncaught aborts
+ if ( xhr.onabort !== undefined ) {
+ xhr.onabort = errorCallback;
+ } else {
+ xhr.onreadystatechange = function() {
+
+ // Check readyState before timeout as it changes
+ if ( xhr.readyState === 4 ) {
+
+ // Allow onerror to be called first,
+ // but that will not handle a native abort
+ // Also, save errorCallback to a variable
+ // as xhr.onerror cannot be accessed
+ window.setTimeout( function() {
+ if ( callback ) {
+ errorCallback();
+ }
+ } );
+ }
+ };
+ }
// Create the abort callback
- callback = xhrCallbacks[ id ] = callback("abort");
+ callback = callback( "abort" );
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;
@@ -131,6 +162,6 @@ jQuery.ajaxTransport(function( options ) {
}
};
}
-});
+} );
-});
+} );