문제

I have an angular frontend with a rails backend.

I have angular code like this:

$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;
});

I kept getting the No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4000' is therefore not allowed access. error, so I used https://stackoverflow.com/a/17815546/561634 so my config/application.rb has:

config.action_dispatch.default_headers = {
  'Access-Control-Allow-Origin' => '*',
  'Access-Control-Request-Method' => '*'
}

inside it. Unfortunately, this hasn't changed the error.

Thanks for all help!

도움이 되었습니까?

해결책

Mare sure you don't have an error on your back-end that would cause an "500 - Internal server error" because in that case the "Access-Control" headers may not be send.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top