From 484cea1b5651d215a24d3a6827663a4e16a6a253 Mon Sep 17 00:00:00 2001 From: jaubourg Date: Wed, 7 Mar 2012 15:39:39 +0100 Subject: [PATCH] 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. --- src/ajax/xhr.js | 8 +++++++- test/data/1x1.jpg | Bin 0 -> 693 bytes test/unit/ajax.js | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 test/data/1x1.jpg 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 new file mode 100644 index 0000000000000000000000000000000000000000..b0d69110f93be60daf95d40b14fa1a95ebdb7850 GIT binary patch literal 693 zcmex=_1P|rX?qqI0P zFI~aY%U!`Mz|~!$%*;qrN1?DZF(yimrOjKe5@ci+Wc+`GK_2KyRz@&jfC5G)W)@a9 zb`DN1ZlHp#0t`%y%*;$I%&e>|EI`$@KzRlhK~^C}Lq|5@z(jVXLJ_0Ji3>TDoi-j6 z4Z8S2#W<;`iIYoATtZSxRZU$(Q_IBE%-q7#%Gt%$&E3P(D>x)HEIcAIDmf)JEj=SM ztGJ}Jth}PKs=1}Lt-YhOYtrN?Q>RUzF>}_U#Y>hhTfSoDs!f}>Y~8kf$Ie}c4j(ys z?D&b3r!HN-a`oEv8#iw~eDwIq(`V0LynOZX)8{W=zkUDl^B2fpj10^WZvjb&$I$#G z2=o^d3kx#~JIG&*Oyxk#EXcyDXviky7|5PjD6C}E$RXl1apA^;oXW;QA4HRiE^>*f um^@Vd2=W@(XT*7|i7cPNJ%;etEe0NDMquPI3o_U%a^9|2F~d-svC! literal 0 HcmV?d00001 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 ); });