Opened 9 years ago
Closed 9 years ago
#14533 closed bug (duplicate)
Content-Type of application/json with Content-Length: 0 causes jQuery to fail the request
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 2.1.0-beta1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Content-Type of application/json with Content-Length: 0 causes jQuery to fail the request.
The reasoning is that the empty string is not valid JSON. Whilst, technically correct (the best kind of correct!), jQuery shouldn't really fail in such a non-intuitive way.
The Content-Type should be used as a 'best try first' parsing for the response. If the response says "application/banana" by all means, try to parse it as a banana, but if it's a peach, then surely we should be able to continue?
After all, a remote server shouldn't be able to crash our application (barring application programmer error).
Duplicate of #13756.
Certainly a remote server could "crash" your application by returning invalid json, such as
{bad
or an empty string. If you don't trust the server, declare an explicitdataType: text
and parse it yourself, then handle (or ignore) the error.