[英]CORS GET request in jQuery
I'm trying to make a core request that should return a bunch of json data, however for some reason the request fails. 我正在尝试发出一个核心请求,该请求应返回一堆json数据,但是由于某种原因该请求失败。 The code I've done so far is as follows:
到目前为止,我完成的代码如下:
$(document).ready(function () {
var url = 'http://test/v/calls';
$.ajax({
url: url,
beforeSend: function (request) {
request.setRequestHeader("Authorization", "Bearer test");
},
success: function (json) {
console.log("Success", json);
},
error: function (textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});
The response is as follows: 响应如下:
catcher.js:197 OPTIONS http://test/v/calls 401 (Unauthorized)
And: 和:
XMLHttpRequest cannot load http://test/v/calls. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://some_domain' is therefore not allowed access. The response had HTTP status code 401.
Note: the same url with the authorization parameters work fine with in Postman. 注意:具有授权参数的相同url在Postman中可以正常使用。 Can't see what is wrong.
看不出什么毛病。
You need to enable cors on the server. 您需要在服务器上启用cors。 It works in Postman because of the way that postman's protocol handles cross-site-scripting.
由于Postman的协议处理跨站点脚本的方式,因此它在Postman中工作。 What is your server built on?
您的服务器基于什么? And how do you add cors to your endpoints?
以及如何将cors添加到端点? are two questions you could start with.
您可以从两个问题开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.