将数据发布到服务器时出错

时间:2017-05-29 10:57:43

标签: angularjs

我想点击登录API,如果登录成功则会响应用户名和密码,否则会返回错误,但问题是我无法向API发送数据。 这是我的一段代码:

$scope.login=function(){
  $http.post("http://urbanholic.com/drago/index.php/api/users/login",
  {identity:$scope.data.identity, password:$scope.data.password})
   .then(function(response){
     $scope.responseMsg=response.data;
    },function(error){
     window.alert("error");
   });
  }

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

$scope.login=function(){
var data = $.param({
     identity:$scope.data.identity,
     password:$scope.data.password
        });

 $http.post("http://urbanholic.com/drago/index.php/api/users/login", data)
 .success(function (response, status, headers, config) {
            $scope.responseMsg=response.data;
        })
        .error(function (data, status, header, config) {
             window.alert("error");
        });
 };
相关问题