Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No 'Access-Control-Allow-Origin' header error #50

Open
ghost opened this issue Apr 3, 2017 · 2 comments
Open

No 'Access-Control-Allow-Origin' header error #50

ghost opened this issue Apr 3, 2017 · 2 comments

Comments

@ghost
Copy link

ghost commented Apr 3, 2017

I'm attempting to consume the api using angular here. Here is my html. Below that is the error I'm seeing in the console. Do we need to add headers for CORS on the server side? Am I overlooking something?

HTML

<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl"> 

<p>Representative</p>

<h1>{{rep}}</h1>

</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
  $http.get("https://derby-pie-politics.herokuapp.com/legislator/40")
  .then(function(response) {
      $scope.rep = response.data;
  });
});
</script>

</body>
</html>

Console

XMLHttpRequest cannot load https://derby-pie-politics.herokuapp.com/legislator/40. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://shaneashford.com' is therefore not allowed access.

@thebouv
Copy link

thebouv commented Apr 3, 2017

Far, FAR too long since I Java'd the things, but since this is Spring MVC, this should help someone make a PR to help with this:

https://spring.io/blog/2015/06/08/cors-support-in-spring-framework

But I think you'd just need to add the @CrossOrigin annotation above line 29's @Controller. It defaults to wildcard origin which is what we want.

@rkahne
Copy link
Contributor

rkahne commented Apr 3, 2017

I've pinged @LilacLlama about this -- hopefully she can confirm that this is the issue. She's the Java Queen of this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants