When we are accessing data from server using angularjs we are getting a CORSE-Error
Our code:
var app = angular.module("app", []);
app.controller("Ctrl", function($scope, $http) {
$scope.survey = true;
$scope.question = false;
$http.get("http://localhost:8081/NxtLife_Demo/getsurveyall").success(function(data) {
$scope.surveys = data;
});
});
Controller-code:
@RequestMapping(value = "/getsurveyall", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody String getSurveyAll() throws JsonProcessingException {
Set<SurveyRecords> records = new HashSet<SurveyRecords>();
records.addAll(surveyService.getSurveyAll());
return new ObjectMapper().writeValueAsString(records);
}
The Error Message:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8081/NxtLife_Demo/getsurveyall. (Reason: CORS header 'Access-Control-Allow-Origin' missing).