【发布时间】:2017-08-09 21:46:11
【问题描述】:
我正在尝试发出一个应该返回一堆 json 数据的核心请求,但是由于某种原因请求失败。目前我做的代码如下:
$(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);
}
});
回复如下:
catcher.js:197 OPTIONS http://test/v/calls 401 (Unauthorized)
还有:
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.
注意:与授权参数相同的 url 在 Postman 中可以正常工作。看不出有什么问题。
【问题讨论】: