【发布时间】:2014-07-30 19:26:45
【问题描述】:
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.
当我尝试从我的代码中运行我的网络服务时,我收到了这个错误。我试图找到它并尝试了许多我在网上找到的建议的解决方案。粘贴下面的代码。
<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>
和controller form对应的js是:
app.controller('LoginController', ['$http', '$scope', function ($scope, $http) {
$scope.login = function (credentials) {
$http.get('http://mywebservice').success(function ( data ) {
alert(data);
});
}
}]);
当我从 URL 栏中点击它时,网络服务工作正常。如何解决问题?请帮忙!
【问题讨论】:
-
$http.get('mywebservice').success(function ( data ) { alert(data); }); } 我认为你错过了 url 中的“'”。
-
你没有任何解决方案可以接受吗?
标签: angularjs ajax cors cross-domain