Javascript 错误回调 {"readyState":4,"status":200,"statusText":"success"}
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14713489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error callback with {"readyState":4,"status":200,"statusText":"success"}
提问by Dario Rusignuolo
I have this urlcall. the url returns a json object as expected (direct browser call) but when I do that via ajax with the follow lines
我有这个url电话。该 url 按预期返回一个 json 对象(直接浏览器调用),但是当我通过 ajax 执行此操作时,请使用以下几行
$.ajax({
url: url,
type: "GET",
dataType:"jsonp",
success: function(data) {
alert(data);
},
error : function(error) {
alert("no good "+JSON.stringify(error));
}
});
it returns me
它返回我
no good {"readyState":4,"status":200,"statusText":"success"}
I know there's others similar questions on stackoverflow, but nobody seems solved it.
我知道在 stackoverflow 上还有其他类似的问题,但似乎没有人解决它。
回答by Quentin
That suggests that the HTTP request was successful but the attempt to parse the data was not.
这表明 HTTP 请求成功,但解析数据的尝试没有成功。
i.e. that the data was not formatted as JSONP.
即数据未格式化为 JSONP。
回答by Dario Rusignuolo
these changes solved my problem.
这些变化解决了我的问题。
//Server side
//服务器端
echo $_GET['callback'] . '('.json_encode($data_to_encode).')';
//js
//js
$.ajax({
url: url+"?callback=?",
type: "GET",
dataType:"jsonp",
success: function(data) {
alert(data);
},
error : function(error) {
alert("no good "+JSON.stringify(error));
}
});
回答by Mikail G.
I've just had the exact same issue,{"readyState":4,"status":200,"statusText":"success"}
我刚刚遇到了完全相同的问题,{"readyState":4,"status":200,"statusText":"success"}
it was because I forgot to remove in my php script an echo "hello"; statment which I previously made for testing reasons, so my php script was sending a string along with JSON, that was my silly mistake maybe You have got the same too
这是因为我忘记在我的 php 脚本中删除 echo "hello"; 我之前出于测试原因所做的声明,所以我的 php 脚本发送了一个字符串和 JSON,这是我的愚蠢错误,也许你也有同样的错误

