Skip to content
Browse files

Fixes #11426: getting the responseText of an xhr should be tried/caug…

…ht because of IE's inability to give access to binary data. Unit test added.
  • Loading branch information...
1 parent 014b2a5 commit 484cea1b5651d215a24d3a6827663a4e16a6a253 @jaubourg jaubourg committed Mar 7, 2012
Showing with 21 additions and 1 deletion.
  1. +7 −1 src/ajax/xhr.js
  2. BIN test/data/1x1.jpg
  3. +14 −0 test/unit/ajax.js
View
8 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
View
BIN test/data/1x1.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
14 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 );
});

0 comments on commit 484cea1

Please sign in to comment.
Something went wrong with that request. Please try again.