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栏点击它时,网络服务工作正常.如何解决问题?请帮忙!