diff options
-rw-r--r-- | src/ajax/xhr.js | 8 | ||||
-rw-r--r-- | test/data/1x1.jpg | bin | 0 -> 693 bytes | |||
-rw-r--r-- | test/unit/ajax.js | 14 |
3 files changed, 21 insertions, 1 deletions
diff --git a/src/ajax/xhr.js b/src/ajax/xhr.js index a87c32392..013863d4e 100644 --- a/src/ajax/xhr.js +++ b/src/ajax/xhr.js @@ -148,7 +148,13 @@ if ( jQuery.support.ajax ) { if ( xml && xml.documentElement /* #4958 */ ) { responses.xml = xml; } - responses.text = xhr.responseText; + + // When requesting binary data, IE6-9 will throw an exception + // on any attempt to access responseText (#11426) + try { + responses.text = xhr.responseText; + } catch( _ ) { + } // Firefox throws an exception when accessing // statusText for faulty cross-domain requests diff --git a/test/data/1x1.jpg b/test/data/1x1.jpg Binary files differnew file mode 100644 index 000000000..b0d69110f --- /dev/null +++ b/test/data/1x1.jpg diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 38ce7c479..cca457db1 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -2322,6 +2322,20 @@ test("jQuery.ajax - abort in prefilter", function() { }); +test( "jQuery.ajax - loading binary data shouldn't throw an exception in IE (#11426)", 1, function() { + stop(); + jQuery.ajax( url( "data/1x1.jpg" ), { + success: function( data ) { + ok( data === undefined || /JFIF/.test( data ) , "success callback reached" ); + start(); + }, + error: function( _, __, error ) { + ok( false, "exception thrown: '" + error + "'" ); + start(); + } + }); +}); + test("jQuery.ajax - active counter", function() { ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active ); }); |