JZw*_*ige 42 javascript ajax jquery json jsonp
我正在使用以下代码进行跨域JSONP调用:
jQuery.ajax({
async: true,
url: 'http://mnews.hostoi.com/test.json',
dataType: 'jsonp',
method: "GET",
error: function (jqXHR, textStatus, errorThrown) {
console.log(textStatus + ': ' + errorThrown);
},
success: function (data, textStatus, jqXHR) {
if (data.Error || data.Response) {
exists = 0;
}
}
});
Run Code Online (Sandbox Code Playgroud)
在Firebug中调试时,我收到以下错误:
SyntaxError: missing ; before statement
Run Code Online (Sandbox Code Playgroud)
但是,当我通过像jsonlint.com这样的工具传递我的json对象(通过JQ代码中的链接可用)时,它说它是有效的JSON.我也没有发现任何异常现象.怎么会返回语法错误?它是一些JSONP细节我没有得到或什么?
{"news":[ {
"sentences": [
"Neuroscientists have discovered abnormal neural activity...",
"The researchers found that these mice showed many symptoms...",
"\"Therefore,\" the study authors say, \"our findings provide a novel.."
],
"summaryId": "ZJEmY5",
"title": "Abnormal neural activity linked to schizophrenia"
}]}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
该错误是因为它返回JSON而不是JSONP.
JSONP应该看起来像
someCallBackString({ The Object });
Run Code Online (Sandbox Code Playgroud)