Angularjs HTTP POST调用以在deployd中验证登录失败 - 返回400错误

时间:2016-10-14 16:38:27

标签: javascript angularjs http http-post deployd

尝试使用angularJS中的以下http post请求到deployd,其中Collection用户包含数据用户名和密码,

  angular.module("sportsStoreAdmin")
    .constant("authUrl", "http://localhost:2403/users/login")
    .controller("authCtrl", ['$scope','$http','$location','authUrl', function($scope, $http, $location, authUrl) {

      $scope.authenticate = function (user, pass) {
        $http.post(authUrl, {
          username: user,
          password: pass
        }, {
          withCredentials: true
        }).success(function (data) {
          $location.path("/main");
        }).error(function (error) {
          $scope.authenticationError = error;
        });
      };

  }]);

当尝试使用上面的url对deployd进行身份验证登录时,deployd给出了以下错误: -

http://localhost:2403/users/login无法加载资源:服务器响应状态为400(错误请求)。

可能是什么问题?

1 个答案:

答案 0 :(得分:0)

以下代码是登录用户的最佳方式:

$('form').submit(function() {
  var username = $('#username').val();
  var password = $('#password').val();
  dpd.users.login({username: username, password: password}, function(session, error) {
    if (error) {
      alert(error.message);
    } else {
      location.href = "/welcome.html";
    }
  });
  return false;
});

“填写”HTML登录表单, #username #password 作为输入标记及其各自的ID。

有关更多参考资料,请参阅此示例: https://github.com/deployd/examples