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

前端 未结 2 1166
温柔的废话
温柔的废话 2020-12-31 06:30

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?

相关标签:
2条回答
  • 2020-12-31 07:00

    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.

    0 讨论(0)
  • 2020-12-31 07:04

    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.

    0 讨论(0)
提交回复
热议问题