【发布时间】:2014-08-18 06:24:33
【问题描述】:
我正在使用 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.
我的功能如下:
$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 来开发这个移动应用程序。
提前致谢
【问题讨论】:
标签: angularjs angularjs-directive xmlhttprequest cors same-origin-policy