Skip to content

Commit 484cea1

Browse files
committed
Fixes #11426: getting the responseText of an xhr should be tried/caught because of IE's inability to give access to binary data. Unit test added.
1 parent 014b2a5 commit 484cea1

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/ajax/xhr.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,13 @@ if ( jQuery.support.ajax ) {
148148
if ( xml && xml.documentElement /* #4958 */ ) {
149149
responses.xml = xml;
150150
}
151-
responses.text = xhr.responseText;
151+
152+
// When requesting binary data, IE6-9 will throw an exception
153+
// on any attempt to access responseText (#11426)
154+
try {
155+
responses.text = xhr.responseText;
156+
} catch( _ ) {
157+
}
152158

153159
// Firefox throws an exception when accessing
154160
// statusText for faulty cross-domain requests

test/data/1x1.jpg

693 Bytes
Loading

test/unit/ajax.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,6 +2322,20 @@ test("jQuery.ajax - abort in prefilter", function() {
23222322

23232323
});
23242324

2325+
test( "jQuery.ajax - loading binary data shouldn't throw an exception in IE (#11426)", 1, function() {
2326+
stop();
2327+
jQuery.ajax( url( "data/1x1.jpg" ), {
2328+
success: function( data ) {
2329+
ok( data === undefined || /JFIF/.test( data ) , "success callback reached" );
2330+
start();
2331+
},
2332+
error: function( _, __, error ) {
2333+
ok( false, "exception thrown: '" + error + "'" );
2334+
start();
2335+
}
2336+
});
2337+
});
2338+
23252339
test("jQuery.ajax - active counter", function() {
23262340
ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active );
23272341
});

0 commit comments

Comments
 (0)