Bug Tracker

Modify

Ticket #11426 (closed bug: fixed)

Opened 2 years ago

Last modified 18 months ago

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:
Blocking: Blocked by:

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

Change History

comment:1 Changed 2 years ago by jaubourg

  • Status changed from new to closed
  • Resolution set to fixed

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 2 years ago by jaubourg

  • Priority changed from undecided to low
  • Component changed from unfiled to ajax
  • Milestone changed from None to 1.7.2

comment:3 Changed 18 months ago by anonymous

jQuery

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.