I have an issue related to CORS. I'm writing client-server app using angular and Spring. When I want to send some HTTP Request, Browser shows that there is a "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8080/..." error. I've deployed REST on localhost using Tomcat, and now I try to consume any response using angular, deployed with "npm" server, but I can't do it because of CORS issue. What am I doing wrong? Here is the code Snippets:
Server side:
@RequestMapping(value="/dummy", consumes="application/json", method=RequestMethod.GET)
public @ResponseBody String dummy() {
return "LOL";
}
Client side:
var authorizationApp = angular.module("authorizationApp", ['PageController','ngRoute']);
authorizationApp.config(function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
});
authorizationApp.config(['$routeProvider', function($routeProvider) {
.....
}])
var pageController = angular.module('PageController',[])
pageController.controller('PageCtrl',['$scope', '$routeParams', '$location', '$http', function($scope, $routeParams, $location, $http) {
..................................
$scope.someFunc = function() {
$http.get("http://localhost:8080/rabota/student/dummy")
.success(function(data, status,headers,config) {
alert("sent");
})
.error(function(data, status,headers,config) {
alert(":-(");
})
}
}])