小编Ru1*_*u11的帖子

请求的资源AngularJS上没有"Access-Control-Allow-Origin"标头

XMLHttpRequest cannot load http://mywebservice. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)

当我尝试从我的代码中运行我的Web服务时,我收到此错误.我试着找到它并尝试了许多我在网上找到的解决方案.粘贴下面的代码.

<form name="LoginForm" ng-controller="LoginCtrl" ng-submit="init(username,password,country)">
    <label>Country</label><input type="text" ng-model="country"/><br/><br/>
    <label>UserName</label><input type="text" ng-model="username" /></br></br>
    <label>Password</label><input type="password" ng-model="password">
    </br>
    <button type="submit" >Login</button>
</form>
Run Code Online (Sandbox Code Playgroud)

而控制器形成相应的js是:

app.controller('LoginController', ['$http', '$scope', function ($scope, $http) {
    $scope.login = function (credentials) {
    $http.get('http://mywebservice').success(function ( data ) {
        alert(data);
        });
    }
}]);
Run Code Online (Sandbox Code Playgroud)

当我从URL栏点击它时,网络服务工作正常.如何解决问题?请帮忙!

ajax cross-domain cors angularjs

69
推荐指数
3
解决办法
16万
查看次数

标签 统计

ajax ×1

angularjs ×1

cors ×1

cross-domain ×1