mko
mko

Reputation: 22044

Why jQuery consider an 200 response Ajax request with empty content as fail()?

First, there's no cross-region problem at all.

I found if the server response an empty content body, jQuery consider this as fail()?

Why is this?

Upvotes: 15

Views: 4817

Answers (2)

pimlottc
pimlottc

Reputation: 3126

WynandB is correct, however there is an alternate resolution: have the server return HTTP 204 No Content instead, which will make jQuery ignore the parsing error.

Upvotes: 15

WynandB
WynandB

Reputation: 1427

If you're using jQuery >= 1.9 an empty JSON response will be rejected, according to the API documentation:

The JSON data is parsed in a strict manner; any malformed JSON is rejected and a parse error is thrown. As of jQuery 1.9, an empty response is also rejected; the server should return a response of null or {} instead.

Upvotes: 19

Related Questions