我正在尝试从API请求数据,我在POSTMAN中尝试过,并且API工作正常,但是当我在ajax中尝试它时,没有数据。 我的代码:
$.ajax({
url: "http://food2fork.com/api/search",
beforeSend: function (xhrObj) {
// Request headers
xhrObj.setRequestHeader("Accept", "application/json");
},
data: { "q": a, "key": "38008dc1ca51f61c514c7e1393d55372" },
type: "GET",
dataType: 'json',
success: function (data) {
var list = data.recipes;
alert(list[0].title);
Builddivs(list);
}
});
我也试过
$.get('http://food2fork.com/api/search', { q: a,key:"38008dc1ca51f61c514c7e1393d55372" }, function(data) {
alert(1);
var list = data.recipes;
alert(list[0].title);
});
它也不起作用...... 这是文档的链接 http://food2fork.com/about/api