Side navigation
#13459 closed bug (notabug)
Opened February 15, 2013 02:57PM UTC
Closed February 15, 2013 03:10PM UTC
Last modified February 22, 2013 08:39PM UTC
Questionable behavior in 1.9.1 with $.ajax.done
Reported by: | manchagnu@gmail.com | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | git |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
If I make a request using dataType as "JSON" and the server sends back a "200 ok" with an empty body, my ajax call throws a parser error:
"parsererror",
SyntaxError: {message: "Unexpected end of input"}
jQuery 1.8.3 did report a success, 1.9.1 reports a failure.
It is arguable that one is "more correct" than the other. Was this an intentional change? Can this regression be addressed?
Thanks!!
Miguel
Attachments (0)
Change History (2)
Changed February 15, 2013 03:10PM UTC by comment:1
resolution: | → notabug |
---|---|
status: | new → closed |
Changed February 22, 2013 08:39PM UTC by comment:2
This issue also occurs when the response's content type is application/json. In a perfect world, the server would either remove that content-type header or respond with a valid JSON object... but I think it would be beneficial if jQuery could guard against this scenario by not trying to convert an empty response to JSON (as it did before 1.9).
If
dataType: "json"
then the server should send back JSON and not an empty body. Version 1.1.1 of the jQuery Migrate plugin will be coming out soon and will let you run the old code without change. Alternate solutions are here:https://github.com/jquery/jquery-migrate/blob/master/warnings.md#jqmigrate-jqueryparsejson-requires-a-valid-json-string