您好我是AJAX和CURL的新手。我正在尝试从API(https://grocerybear.com/)中提取数据,这是我在JQUERY中用来访问API的代码;
$.ajax({
type: "POST",
url: "https://grocerybear.com/getitems",
dataType: 'jsonp',
data: {"city":"Austin", "product":"eggs", "num_days": 7},
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'key = my key');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Acess-Control-Allow-Origin', '*');
}
});
运行代码后,我在控制台中收到以下错误;
好的我将我的代码更新为以下内容:
$.ajax({
type: "POST",
url: "https://grocerybear.com/getitems",
ContentType: "application/json",
dataType: 'jsonp',
data: {"city":"Austin", "product":"eggs", "num_days": 7},
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'key = mykey');
}
});
现在我收到以下错误:
无法加载资源:服务器响应状态为405(METHOD NOT ALLOWED)