Side navigation
#11426 closed bug (fixed)
Opened March 01, 2012 09:12PM UTC
Closed March 07, 2012 02:39PM UTC
Last modified October 18, 2012 01:50PM UTC
jQuery.ajax() always fails when requesting JPG images in IE
Reported by: | leilers@vistaprint.com | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | 1.7.2 |
Component: | ajax | Version: | 1.7.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
- jQuery version: all (verified bug exists in 1.7.1)
- Affected browsers: IE (tested IE6-9). Doesn't happen in any other browser.
$.ajax() executes the error callback instead of the success callback when a request is made for a jpeg in IE.
The exception is:
'Could not complete the operation due to error c00ce514.'
Minimal repro case URL:
http://dl.dropbox.com/u/45268548/jquerybug/test.htm
The exception is thrown in the ajaxTransport definition for XHR, in the callback function. It is caused by attempting to access XmlHttpRequest.responseText when the response is binary JPEG data (doesn't affect GIF or PNG). This is line 8148 of jquery-1.7.1.js:
status = xhr.status; responseHeaders = xhr.getAllResponseHeaders(); responses = {}; xml = xhr.responseXML; // Construct response list if ( xml && xml.documentElement /* #4958 */ ) { responses.xml = xml; } responses.text = xhr.responseText; //IE exception thrown here // Firefox throws an exception when accessing // statusText for faulty cross-domain requests try { statusText = xhr.statusText; } catch( e ) { // We normalize with Webkit giving an empty statusText statusText = ""; }
The solution I'd recommend is to simply wrap the call to xhr.responseText with a try/catch, where the catch block sets responses.text to null. While this wouldn't fix the inability to access the binary data (IE's javascript doesn't seem to be able handle the binary data from responseBody in general), it would at least behave correctly in other regards- calling the success handler, and allowing access to the response headers (which can be very useful for transmitting metadata along with images).
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.
Changeset: 484cea1b5651d215a24d3a6827663a4e16a6a253