Angularjs的HTTP POST调用在部署中验证登录失败-返回400错误

Angularjs HTTP POST call to authenticate login in deployd failed- 400 error returned

本文关键字:失败 登录 返回 错误 验证 HTTP POST 调用 部署 Angularjs      更新时间:2023-09-26

尝试在angularJS中部署下面的http post请求,使用包含数据的Collection users用户名和密码,

  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来验证登录时,deploy给出以下错误:-

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

有什么问题吗?

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

$('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