Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#11426 closed bug (fixed)

jQuery.ajax() always fails when requesting JPG images in IE

Reported by: leilers@… Owned by:
Priority: low Milestone: 1.7.2
Component: ajax Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:


  • 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).

Change History (3)

comment:1 Changed 11 years ago by jaubourg

Resolution: fixed
Status: newclosed

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

comment:2 Changed 11 years ago by jaubourg

Component: unfiledajax
Milestone: None1.7.2
Priority: undecidedlow

comment:3 Changed 11 years ago by anonymous


Note: See TracTickets for help on using tickets.