Bug Tracker

Opened 10 years ago

Closed 10 years ago

#13739 closed bug (invalid)

Context-type: text/plain interpreted as JSON, throws error

Reported by: [email protected] Owned by: [email protected]
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:


I am seeing a significant difference in behavior between 1.8.3 and 1.9.1/2.0b2. jQuery migrate is silent on the issue.

Steps to repro:

Submit an ajax request using the params:

contentType: 'application/json',
type: 'POST',
dataType: 'json',
processData: false

Return from the server a response with:

200 OK

In the 1.9.1 / 2.0b2 releases, this response is an error ("parsererror"). Seems it is being parsed as JSON, despite the response indicating it is not JSON.

In the 1.8.3 code line, this response is interpreted as a success.

The difference seems to be rooted in logic changes in the local function ajaxConvert.

Change History (4)

comment:1 Changed 10 years ago by dmethvin

Owner: set to [email protected]
Status: newpending

Why are you saying dataType: 'json' if the returned data type isn't JSON? If you expect text, say it's text.

comment:2 in reply to:  1 Changed 10 years ago by anonymous

Replying to dmethvin:

Why are you saying dataType: 'json' if the returned data type isn't JSON? If you expect text, say it's text.

First, thank you for replying. I appreciate your time considering this.

We are sometimes asked to interact with servers not under our control. One such server returns json mime-type when it has new data and text mime-type when it wishes to return "". The correctness of this is worthy of debate. But it is immutable for the purposes of discussing this jQuery issue.

If I ask for dataType: text, then I lose the benefits of automatic JSON parsing. If I ask for dataType: json, then I get errors when parsing "".

I see an undocumented difference in behavior between 1.8 and 1.9+. I mention it because it's what good citizens do. I leave it to others to decide: a) to put this compatibility behavior back into 1.9+, b) to add detection of the change to jquery-migrate, c) add the changed behavior to release notes, or d) do nothing.

comment:3 Changed 10 years ago by jaubourg

Simple solution: don't provide a dataType and let jQuery use the Content-Type response header to determine proper dataType?

comment:4 Changed 10 years ago by trac-o-bot

Resolution: invalid
Status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

Note: See TracTickets for help on using tickets.