jQuery1.4.2的json提示parsererror问题
来源:互联网 发布:网络用语ps什么意思 编辑:程序博客网 时间:2024/05/17 22:49
今天用到jquery来处理ajax,用到了json。但是很诧异,jquery的ajax回调时一直调用了error函数(一直提示parsererror异常),success函数一次没执行过 。代码如下:
1
$.ajax({
2
type:
'POST'
,
3
url:
'/go.php?p=chat.chatCenter&a=send'
,
4
dataType:
'json'
,
5
data:
'style='
+Tstyle+
'&content='
+content,
6
success:
function
(data){$.chatCenter.sendEnd(data);},
7
error:
function
(data,t){alert(
"系统异常["
+t+
"]"
);$.chatCenter.sendEnd();}
8
});
服务器返回结果为:{id:"1",data:"none"}
搞了很久,我把库换回1.3.1可以成功~~lol,最后发现是jQuery1.4.2这个版本引起的,1.4.2中jq把JSON的解析由原来的eval改为极其严格的$.parseJSON()来处理了。我在官方的说明文档中找到的,如下:
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.)
http://api.jquery.com/jQuery.ajax/
就是说 jQuery 1.4对服务端返回的JSON 数据要求比较严格,必须严格按照JSON的标准来了。
下面我把$.parseJSON的说明文档也摘要下来:
jQuery.parseJSON( json )
Passing in a malformed JSON string will result in an exception being thrown. For example, the following are all malformed JSON strings:
{test: 1} (test does not have double quotes around it). 译:test两边必须有双引号 {"test":1}
{'test': 1} ('test' is using single quotes instead of double quotes). 译:test两边的引号不能为单引号,一定要是双引号
Additionally if you pass in nothing, an empty string, null, or undefined, 'null' will be returned from parseJSON. Where the browser provides a native implementation of JSON.parse, jQuery uses it to parse the string. For details on the JSON format, see http://json.org/.
现在什么都讲究标准啦,我们老老实实按标准来吧。我下面列举几个符合标准的例子:
{"myvalue":1}
{"myvalue":"red"}
{"myvalue":["black",250]}
- jQuery1.4.2的json提示parsererror问题
- jQuery1.4.2的json提示parsererror问题
- jQuery1.4.2的json提示parsererror问题
- 关于jQuery1.4.2的json格式问题
- ajaxSubmit插件jQuery1.4.2版JSON问题
- jQuery:Ajax提示parsererror错误的解决办法
- jquery ajax json parsererror
- jquery ajax json parsererror
- jQuery1.4.2与json格式兼容问题
- jQuery提示parsererror错误解决办法
- jQuery提示parsererror错误解决办法
- 关于JQuery Ajax时出现 parsererror的问题
- JQuery的parsererror错误
- jQuery1.26以上版本"@"的问题
- jquery1.4.*中迎来json新的变化
- .Net+C#+Jquery实现Ajax的json应用。解决parsererror错误
- struts2.1.8.1+jquery1.4.2返回json数据
- struts2.1.8.1+jquery1.4.2返回json数据
- 如何通过解决生词突破SAT阅读高分?
- 手机网络状态
- 浏览器和js交互、NPAPI之NPRuntime开发
- JS Output
- javascript中ajax
- jQuery1.4.2的json提示parsererror问题
- IP_ADD_MEMBERSHIP 失败
- Android工程中三种库的区别:Private 、Referenced、Dependency
- 有用的网站和链接
- Ubuntu14.04安装Devstack
- jquery ajax 跨域调用
- tcpdump 抓包
- Reaver参数表
- Ubuntu15下Qt+libusb开发