Skip to main content

Bug Tracker

Side navigation

#13739 closed bug (invalid)

Opened April 05, 2013 08:59PM UTC

Closed April 23, 2013 08:36AM UTC

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

Reported by: patrick@nestlabs.com Owned by: patrick@nestlabs.com
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:
Description

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
Content-Length:0
Content-Type:text/plain

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.

Attachments (0)
Change History (4)

Changed April 09, 2013 12:11AM UTC by dmethvin comment:1

owner: → patrick@nestlabs.com
status: newpending

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

Changed April 09, 2013 12:25AM UTC by anonymous comment:2

Replying to [comment:1 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.

Changed April 09, 2013 12:39AM UTC by jaubourg comment:3

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

Changed April 23, 2013 08:36AM UTC by trac-o-bot comment:4

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!