aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ajax/xhr.js13
-rw-r--r--test/unit/ajax.js24
2 files changed, 31 insertions, 6 deletions
diff --git a/src/ajax/xhr.js b/src/ajax/xhr.js
index fd4a733e5..db670ff15 100644
--- a/src/ajax/xhr.js
+++ b/src/ajax/xhr.js
@@ -97,12 +97,13 @@ jQuery.ajaxTransport( function( options ) {
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()
);
}
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index 4f0530656..12bf2ab31 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -1660,6 +1660,30 @@ QUnit.module( "ajax", {
};
} );
+if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().responseType !== "string" ) {
+
+ QUnit.skip( "No ArrayBuffer support in XHR", jQuery.noop );
+} else {
+
+ // No built-in support for binary data, but it's easy to add via a prefilter
+ jQuery.ajaxPrefilter( "arraybuffer", function ( s ) {
+ s.xhrFields = { responseType: "arraybuffer" };
+ s.responseFields.arraybuffer = "response";
+ s.converters[ "binary arraybuffer" ] = true;
+ });
+
+ ajaxTest( "gh-2498 - jQuery.ajax() - binary data shouldn't throw an exception", 2, function( assert ) {
+ return {
+ url: url( "data/1x1.jpg" ),
+ dataType: "arraybuffer",
+ success: function( data, s, jqxhr ) {
+ assert.ok( data instanceof window.ArrayBuffer, "correct data type" );
+ assert.ok( jqxhr.response instanceof window.ArrayBuffer, "data in jQXHR" );
+ }
+ };
+ } );
+}
+
QUnit.asyncTest( "#11743 - jQuery.ajax() - script, throws exception", 1, function( assert ) {
// Support: Android 2.3 only