0
我有一個帶有後端軌道的角度前端。'Access-Control-Allow-Origin'問題
我有角這樣的代碼:
$http({method: 'GET', url: 'http://localhost:3000/products.json'}).
success(function(data, status, headers, config) {
$scope.data = data;
}).
error(function(data, status, headers, config) {
$scope.status = status;
});
我一直得到了No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4000' is therefore not allowed access.
錯誤,所以我用https://stackoverflow.com/a/17815546/561634所以我的config/application.rb中有:
config.action_dispatch.default_headers = {
'Access-Control-Allow-Origin' => '*',
'Access-Control-Request-Method' => '*'
}
裏面。不幸的是,這並沒有改變錯誤。
感謝您的幫助!
您設置了哪個網站? 如果site1向site2調用ajax請求,則應將其設置在site1上。對於這個煩人的問題,我放棄了設置該配置,現在我使用jsonp。你也可以試試。 – Mavlarn