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.
I get this error when I try to start my web service from my code. I tried to find this and tried many of the solutions that were offered that I found on the net. Paste the code below.
<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>
And the controller generates the corresponding js:
app.controller('LoginController', ['$http', '$scope', function ($scope, $http) { $scope.login = function (credentials) { $http.get('http://mywebservice').success(function ( data ) { alert(data); }); } }]);
The web service works fine when I hit it from the URL bar. How to solve a problem? Please, help!
angularjs ajax cors cross-domain
Ru11 Jun 10 '14 at 6:16 2014-06-10 06:16
source share