Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/ajax/xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this comment because basically all XHR2 impls are supposed to throw on binary data in cases like ArrayBuffer.

// 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()
);
}
Expand Down
24 changes: 24 additions & 0 deletions test/unit/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -1599,6 +1599,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
Expand Down