您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

jquery ajax json 怪异的问题

2026/1/27 4:17:43发布22次查看
js代码
$.ajax({
type: post,
url: /test1.php,
datatype: json,
timeout : 16000,
data:{cid:n},
success: function(msg){
if(1 == msg.status){
                                                    alert('ok');
}else if(0 == msg.status){
alert('sorry')
}
},
 error: function (jqxhr, textstatus, errorthrown) {    
                                               alert(textstatus+,+errorthrown);    
                                         }   
});
php代码
1);
exit(json_encode($menu));
去除js的datatype: json,正常执行success分支;
使用jquery1.3.2 也正常执行success分支;但只要使用1.6,并且指定datatype:json,立马执行error分支,报“parsererror,no conversion from text to json” json解析问题;
难道php的json_encode()函数,转换数组至json格式也会有问题?
回复讨论(解决方案) 补充:
/test1.php
中的内容,就是上述php代码
因为你有 datatype: json
所以进入 ajax error分支 的前提是返回的数据不是 json 格式的
parsererror,no conversion from text to json (json转换失败)也佐证了这一点
为什么会转换失败呢?多半是你的 php 程序保存成了有 utf-8 bom 头的格式了
这一点你可以通过:
2.php
看到。输出结果中开始的 efbbbf 就是 bom 头
高手,佩服佩服!
给分了。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product