0
我試圖做一個核心請求,應該返回一堆JSON數據,但由於某種原因請求失敗。我迄今所做的代碼如下:在jQuery CORS GET請求
$(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與授權參數在郵差工作正常。看不出有什麼問題。
我在vhost.conf中添加了'Header set Access-Control-Allow-Origin'*「'根據這個帖子:[link](https://enable-cors.org/server_apache.html)。之後,我運行了命令'ln -sf /etc/apache2/mods-available/headers.load /etc/apache2/mods-enabled/headers.load'.Still我得到的迴應是一樣的。 –
我調試了一下,我發現這個:'Www-Authenticate:Bearer realm =「api」'。這是從哪裏來的?它應該不是測試? –