Wednesday, October 4, 2017

Angularjs $http then is not working properly

I get a value of “True” in my response. How come my debugger and alert and AccessGranted() in the .then of my $http is not being invoked. Below is my Script:

app.controller("LoginController", function($scope, $http) {
    $scope.btnText = "Enter";
    $scope.message = "";

$scope.login = function() {
    $scope.btnText = "Please wait...";
    $scope.message = "We're logging you in.";

    $http({
        method: 'post',
        url: '/Login/Login',
        data: $scope.LoginUser
    }).then(function (response) {
            debugger;
            alert(response.data);
            if (response.data == "True") {
              AccessGranted();
            } else {
            $scope.message = response.data;
            $scope.btnText = "Enter";
        } 
    },
    function (error) {
        $scope.message('Sending error: ' + error);
    });
}

$scope.AccessGranted = function() {
    window.location.pathname("/Home/HomeIndex");
}
});

This is in my HomeController

public ActionResult HomeIndex()
{
    var am = new AuditManager();
    var auditModel = new AuditModel()
    {
        AccountId = 0,
        ActionDateTime = DateTime.Now,
        ActionName = "Home",
        ActionResult = "Redirected to Home"
    };
    am.InsertAudit(auditModel);

    return View("Index");
}

Source: AngularJS



from Angular Questions https://angularquestions.com/2017/10/04/angularjs-http-then-is-not-working-properly/
via @lzomedia #developer #freelance #web #lzomedia.com

No comments:

Post a Comment