0

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!

Community
  • 1
  • 1
the_
  • 1,183
  • 2
  • 30
  • 61
  • Which site you set that? If site1 call ajax request to site2, you should set it on site1. For this annoying problem, I gave up to set that config, I use jsonp now. You can also try. – Mavlarn Nov 05 '13 at 05:51

1 Answers1

0

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.

Adrian Neatu
  • 1,989
  • 2
  • 19
  • 34