我有一个带导轨后端的角度前端。
我有这样的角度代码:
$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' => '*'
}
在里面。不幸的是,这并没有改变错误。
感谢大家的帮助!