标签:blog error: escape 服务 对象 返回 sch 成功 style
报错:Uncaught SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at Function.m.parseJSON (jquery.js:8515)
at Object.success (crud.html:45)
at j (jquery.js:3143)
at Object.fireWith [as resolveWith] (jquery.js:3255)
at x (jquery.js:9309)
at XMLHttpRequest.b (jquery.js:9713)
(翻译:不能捕获的语法错误:json数据位置0处发现不能识别的标记<)
原因:json格式错误
json教程见:http://www.w3school.com.cn/json/index.asp
解决办法:
修改为echo json_encode($data,true);
将php的代码调试代码 echo()去掉,就不会再报这样的错误了:
$json = json_encode(array( "resultCode"=>200, "message"=>"查询成功!", "data"=>$data ),JSON_UNESCAPED_UNICODE); //注释掉 /*echo($json);*/
如果使用 $.ajax 时,不需要注释
//不需要注释
echo($json);
如果不是该问题,请检查php文件给返回的data数据,是否标准json格式。如果php文件中有var_dump、echo、注释等,都会对返回的json数据有影响。
标签:blog error: escape 服务 对象 返回 sch 成功 style
原文地址:http://www.cnblogs.com/baiyygynui/p/6815255.html