Why does $.ajax call for json data trigger the error callback when http status code is “200 OK”?

前端 未结 3 1455
伪装坚强ぢ
伪装坚强ぢ 2020-12-20 17:38

I have the following ajax request:

        jQuery.ajax({
            async: true,
            type: \"GET\",
            url: url,
            data: data,
           


        
3条回答
  •  伪装坚强ぢ
    2020-12-20 17:59

    The problem might be that the json data returned from the url is malformed. When the server actually returns something, the http status code is 200. But that doesn't mean that the data is proper json. Check that the stringified json data returned is correctly formed.

    I'm answering my own guestion because I learned this the hard way. I hadn't escaped a "-quote character in my json data. This resulted in very odd behaviour. Luckily the double quote character is pretty much the only character that needs to be escaped from data delivered via JSON. (More on this issue: Where can I find a list of escape characters required for my JSON ajax return type?)

提交回复
热议问题