简体   繁体   中英

Moving to other html through javascript

i'm trying to move to my account.html from my login.html, using javascript, where i in login.html there will be a validation from MongoDB. And if it's the same data, it was supposed to go to acoount.html, but it doesn't. This is my javascript:

.controller('LoginCtrl', function($scope, $state, $ionicPopup, AuthService) {
  $scope.data = {};

  $scope.login = function(data) {
           var formdata = {

                   num : $("#num").val(),
                   pw : $("#pw").val()  
            };

            var Jformdata = JSON.stringify(formdata);
            //var url = $location.url();
            console.log(Jformdata);

            $.ajax({
                url : "/ProjectSinarmas/submit",
                context : document.body,
                type : 'POST',
                data : Jformdata,
                contentType : "application/json"
            }).done(function (response){
                //console.log(response);
                if(response == "true"){
                    //$state.go('main.account');
                    var path = $location.path("http://localhost:8089/ProjectSinarmas/templates/account.html");
                    alert("Login Success");
                }else{
                    $scope.showAlert('Nomer Telephone dan PIN Salah');
                }

            });


        };

I got this error response from my html:

controllers.js:53 Uncaught ReferenceError: $location is not defined

Thanks before, and have a nice day.

You need to call $location in Controller check below

.controller('LoginCtrl', function($scope, $state,$location, $ionicPopup, AuthService) {


 //code........

}

In addition to adding $location to your controller, my guess is you might also need to use the AngularJS $http method (or $post) method instead of $ajax, so that AngularJS knows when your request is completed and handles the scope update.

also change:

   var path = $location.path("http://localhost:8089/ProjectSinarmas/templates/account.html");

to:

    $location.path("http://localhost:8089/ProjectSinarmas/templates/account.html");

no need to put in the path var if its not used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM