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
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