如何解决CORS即angularjs同源策略
问题描述:
我开发的angularjs,我必须作出调用Web服务的移动应用程序。但是,当我正在与 $ http.get
电话这是给下面的错误。
I am developing a mobile application in angularjs where I have to make call to web service. But, when I am making the call with $http.get
it is giving the following error.
XMLHttpRequest cannot load http://example.com/First_Step.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8020' is therefore not allowed access.
我给这家功能如下:
My function for this is as follows:
$scope.firstStepClick = function() {
appSvc.selectedItem = "firstStep";
$rootScope.go('parent/firststep', 'slideLeft');
delete $http.defaults.headers.common['X-Requested-With'];
$http.get("http://example.com/First_Step.json").success(function(data) {
$scope.firstStepData = data;
}).error(function() {
alert("an unexpected error occured");
});
};
所以,请帮我解决这个问题CORS。我使用HTML5,CSS3和angularjs这个移动应用程序开发。
So, please help me to solve this CORS problem. I am using html5, css3 and angularjs for this mobile app development.
在此先感谢
答
您不必做的角边什么。
You don't have to do anything in the Angular side.
服务器端是一个负责发送权限头,使CORS
The server side is the one responsible to send the rights headers to enable CORS
看看一个这样的: