如何解决CORS即angularjs同源策略 [英] How to resolve CORS ie same origin policy in angularjs

查看:246
本文介绍了如何解决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

看看一个这样的:

http://enable-cors.org/server.html

这篇关于如何解决CORS即angularjs同源策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆