首先,我知道网站上有类似的帖子,但没有一个能解决我的问题。
我想从 Web 服务器获取 JSON 文件。JSON 文件已由 JSONLint 检查,因此验证语法正确。JSON 数据是从类似于以下的 URL 检索的:www.examplewebsite.com/data.json
我的 jQuery Ajax 代码:
$.ajax({
url:url",
dataType:"jsonp",
contentType: "application/json",
type:"get",
success:function(){
console.log("OK");
},
error:function(data,status,error){
console.log(data " "status+" "+error);
}
});
Run Code Online (Sandbox Code Playgroud)
这是错误:
:parsererror 错误:未调用 jQuery222030055767520832166_1465026956736
到目前为止我所做的:
alert("OK");),但我仍然收到错误。错误消息之一是“未调用未定义”Access-Control-Allow-Origin错误更新1
我的json内容(用于测试):
[{
"id": 1,
"first_name": "Sara"
}, {
"id": 2,
"first_name": "Lois"
}, {
"id": 3,
"first_name": "Annie"
}, {
"id": 4,
"first_name": "Gregory"
}, { …Run Code Online (Sandbox Code Playgroud)