使用AJAX从CURL外部服务器获取数据

时间:2017-10-06 19:08:53

标签: jquery ajax curl

您好我是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', '*');
    }
});

运行代码后,我在控制台中收到以下错误;

Error Code

好的我将我的代码更新为以下内容:

$.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)

0 个答案:

没有答案