ajax请求失败但是返回200

来源:互联网 发布:ubuntu java环境搭建 编辑:程序博客网 时间:2024/05/16 09:58

jquery ajax请求成功,返回了数据,但是不进success的问题

1-------------------------dataType: "json"

The documentation states that jQuery:

Evaluates the response as JSON and returns a JavaScript object. (...) The JSON data is parsed in a strict manner; any malformed JSON is rejected and a parse error is thrown.

This means that if server returns invalid JSON with a 200 OK status then jQuery fires the error function and set the textStatus parameter to "parsererror".

Solution: make sure that the server returns valid JSON. It is worth noting that an empty response is also considered invalid JSON; you could return {} or null for example which validate as JSON.

you can check whether a json is valid or not on jsonlint.com


2----------------------------

  1. 返回的数据类型一定要符合定义的数据类型。即如果你定义的 dataType 是 json 类型的,那么返回来的数据一定是 json 才可以,平且不然就会执行 error 里的程序块儿。
   (1) 同时需要特别的注意返回的JSON数据是否是严格的JSON格式.
   (2) 也应该严重关切当后台返回的是一个List 数据(List当中的数据是Json格式)时,有没脏数据即不是严格的JSON格式。
    很隐蔽的可能是数据某一个字段中在开始或末尾含有特殊字符,以"回车键"、"Tab键"等


3----------------------------




http://stackoverflow.com/questions/6186770/ajax-request-return-200-ok-but-error-event-is-fired-instead-of-success

http://my.oschina.net/adwangxiao/blog/78509

http://qianduanblog.com/post/jquery-ajax-status-success-200.html

http://www.googto.com/?q=ajax%20%E8%AF%B7%E6%B1%82%E5%A4%B1%E8%B4%A5%E4%BD%86%E6%98%AF%E8%BF%94%E5%9B%9E200

0 0
原创粉丝点击