I am having this error even though I have headers assigned in angular's $http service:
function Hello($scope, $http) {
$http({
method: 'GET',
url: 'http://localhost:8080/races',
headers: {
'Access-Control-Allow-Headers': 'accept',
'Access-Control-Allow-Methods': 'GET',
'Access-Control-Allow-Origin': '*'
},
}).then(function successCallback(response) {
$scope.races = response;
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
}
This is full error message on console:
XMLHttpRequest cannot load http://localhost:8080/races. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63343' is therefore not allowed access. The response had HTTP status code 403.
HTML:
<!doctype html>
<html ng-app>
<head>
<title>Hello AngularJS</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
<script src="hello.js"></script>
</head>
<body>
<div ng-controller="Hello">
<p>The ID is {{races.raceId}}</p>
<p>The name is {{races.raceName}}</p>
</div>
</body>
</html>
When I open the localhost:8080/races I can fully see the json:
[{"raceId":8446,"raceName":"test1"},{"raceId":8447,"raceName":"test2"}]