[英]jQuery ajax() saying parseerror while json passes jsonlint
I have a simple website with jQuery (1.8.2) doing an ajax call: 我有一个使用jQuery(1.8.2)进行ajax调用的简单网站:
$.ajax({
url: 'http://localhost:1337?callback=?',
dataType: 'jsonp',
crossDomain: true,
success: function(a,b,c) {
console.log('success',a,b,c);
},
error: function(a,b,c) {
console.log('error',a,b,c);
}
});
The webpage has the headers: 该网页具有标题:
Access-Control-Allow-Origin *
Access-Control-Expose-Headers Access-Control-Allow-Origin
Access-Control-Allow-Headers *
the ajax being return'd is: 返回的ajax是:
[{"a":"b"}]
(which also passes JSONlint), The json is being served as application/json
(还传递JSONlint),将json用作application/json
However I get a parse error: 但是我得到一个解析错误:
'error'
[object]
'parsererror'
Error
arguments: undefined
get stack: function () { [native code] }
message: "jQuery18209882410678546876_1355861965752 was not called"
set stack: function () { [native code] }
type: undefined
You will have to return 你将不得不返回
$_GET["callback"] . "('[\"a\":\"b\"]')"
and not just the JSON, because with JSONP jQuery expects to get back executable script code. 不仅是JSON,因为jQuery希望使用JSONP取回可执行脚本代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.