jquery 使用ajax,正常返回后,不执行success的问题

背景:

       在使用到jQuery的ajax时,如果指定了dataType为json,老是不执行success回调,而是执行了error回调函数.

原因:

       然后继续下载了几个jquery版本,如1.3.2,1.4.0的,指定dataType为json都不能执行success回调,只有小于1.3版本的才能执行success回调。

      去jquery的网站找到了在线的api文档看了下,地址:http://api.jquery.com/jQuery.ajax/ ,发现dataType如下的说明 
  "json": Evaluates the response as JSON and returns a JavaScript object. In jQuery 1.4 the JSON data is parsed in a strict manner; any malformed JSON is rejected and a parse error is thrown. (See json.org for more information on proper JSON formatting.) 

  原来是jquery1.4版本以后对json格式要求非常严格了,要满足json.org网站定义的格式才能执行success回调,否则都会出错,无法解析返回的json数据

解决方法:

       修改返回值,使之符合json规范。

       JSON格式总结下,详细的去json.org 查看。 
         1)键名称:用双引号 括起 
         2)字符串:用使用双引号 括起 
         3)数字,布尔类型不需要 使用双引号 括起

原文地址:https://www.cnblogs.com/LionheartCGJ/p/7905316.html