Bug Tracker

Opened 5 years ago

Closed 5 years ago

#15193 closed bug (migrated)

Ajax requests with binary data throw errors in Chrome

Reported by: cbroome Owned by:
Priority: undecided Milestone: None
Component: ajax Version: 2.1.1
Keywords: Cc:
Blocked by: Blocking:

Description

This is related to issue #11426.

Code starting at line 8598:

  complete(
    xhrSuccessStatus[ xhr.status ] || xhr.status,
    xhr.statusText,
    // Support: IE9
    // Accessing binary-data responseText throws an exception
    // (#11426)
    typeof xhr.responseText === "string" ? {
      text: xhr.responseText
    } : undefined,
    xhr.getAllResponseHeaders()
  );

In that ticket, the fix was to throw an exception for IE browsers, however Chrome v36 throws an exception as well when accessing xhr.responseText. I'm not advocating jquery handling binary data, as another ticket left that for the plugins. What I'd like to see is the conditional:

    typeof xhr.responseText === "string" 

changed to something safer:

    (xhr.responseType === "text" && xhr.responseText === "string")

Or something similar, so long as that check doesn't throw an exception. As it is the current state prevents launching the 'complete' callback for any binary data response, even though 'text' is an inessential parameter (defaulted to undefined).

Thanks.

Change History (2)

comment:1 Changed 5 years ago by cbroome

Actually, thinking on it more, something like:

( [ "arraybuffer", "blob" ].indexOf( xhr.responseType ) < 0 )  && xhr.responseText === "string")

would be safer all to existing functionality.

Last edited 5 years ago by cbroome (previous) (diff)

comment:2 Changed 5 years ago by m_gol

Resolution: migrated
Status: newclosed
Note: See TracTickets for help on using tickets.