小编Ani*_*dya的帖子

如何解决CORS即AngularJS中的相同来源策略

我正在用angularjs开发一个移动应用程序,在该应用程序中必须调用Web服务。但是,当我拨打电话时$http.get,出现以下错误。

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. 
Run Code Online (Sandbox Code Playgroud)

我的功能如下:

$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");
    });
};
Run Code Online (Sandbox Code Playgroud)

因此,请帮助我解决此CORS问题。我正在为此移动应用程序开发使用html5,css3和angularjs。

提前致谢

xmlhttprequest same-origin-policy cors angularjs angularjs-directive

0
推荐指数
1
解决办法
6167
查看次数