angularjs - Login Angular - PHP error -


i'm creating app angularjs , php, try connect file php of other domain, when call file never show me info.this controller...

myapp.controller('loginctrl', function loginctrl($scope, $http) {  $scope.dologin = function()  {             $http({         method: 'post',          url: 'http://www.domain.com/login.php?',         data:          {              'usuario'   : $scope.usuario,              'password'  : $scope.password,             'type'      : 1         },      })       .success(function(data, status)     {         alert('validado');         $scope.data = data;         if(data == 'no encontrado')         {             $scope.aviso = 'usuario o contraseƱa invalidos';         }         else          {             $scope.aviso = 'bienvenido';         }      })     .error(function(data, status) {              $scope.data = data || "false";             $scope.status = status;               $scope.aviso = 'ha pasado algo inesperado';     });  }; 

});

and template...

<div  class="container">     <hr>     <div class="span5" >          <form>             <h2 class="form-signin-heading">login </h2>             <label>usuario</label>             <input type="text"      ng-model="usuario">             <label>contraseƱa</label>             <input type="password"  ng-model="password">             <br>             <input type="submit" value="entrar" ng-click="dologin()" class="btn btn-primary">             <div>{{aviso}}</div>         </form>     </div> </div> 

but never in .success(), when use mozilla , chorme firebug empty, when use:

 $http.get('http://www.domain.com/login.php?usuario=user1&password=123456&type=1')     .success(function(data, status).... appears next error:   xmlhttprequest cannot load http://www.domain.com/login.php?usuario=user1&password=123456&type=1. origin http://localhost:8081 not allowed access-control-allow-origin. 

i have been unable fix it, if know answer i'll appreciate it.

thanks

you have create local proxy script or enable cors. cors usable browsers, not all. using local proxy script safest bet. basically, ajax requests go through proxy passing remote address use thereby keeping in line same-domain access policy.

a php proxy: https://github.com/eslachance/php-transparent-proxy

more on cors: http://en.wikipedia.org/wiki/cross-origin_resource_sharing


Comments