我创建了一个以 json 格式返回数据的 API,现在我正在创建一个应用程序来通过接收数据并在页面上使用它来测试 API。但是,我的 ajax 代码(见下文)由于某种原因失败,并且错误只是“错误”(错误:错误)。
代码有什么问题?
编码:
$.ajaxSetup ({
url: "http://localhost:8000/products", // <--- returns json
type: "GET",
headers:{
"Accept":"application/json",
"Content-type":"application/x-www-form-urlencoded"
}
})
$.ajax({
success: function(data){
console.log("You made it!");
},
error: function(xhr) {
console.log("Error: " + xhr.statusText);
}
}).done(function(data){
console.log(data);
})
这是我在 Chrome (Inspector -> Network) 中获得的信息:
名称: products localhost/,方法: GET,状态:(已取消),类型: Pending,发起者: jquery-latest.js:8434 脚本,大小: 13B 0B,时间: 95ms 0.0天