0

is there a way to use base_url() in angularJS?

here's my code:

it worked fine. but I'm just curious if there's a way for me to use base_url like in the comment of the code, than typing the whole fixed url.

$scope.login = function(){
    console.log($scope.users);
    var inputs = 'myData=' + JSON.stringify($scope.users);
    $http({
        method:'POST',
        url:'lib/login_c.php',
        data: inputs,
        headers:{'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'}
    }).success(function(res){
        console.log(res);
        if(res == 1){
             $window.location.href = "http://localhost/angularjs/index.php";
             //$windows.location.href=baseurl() + '/index.php';
        }else{
            $scope.message = true;
        }
    });
};

1 Answer 1

1

You can just use a / to use root url. And in your case you want to href to the index page just do like this:

$window.location.href = "index.php"

You may also find this helpful:

"./index.php" //dot is for root
Sign up to request clarification or add additional context in comments.

1 Comment

Hello sir.. can I ask you something about user authentication? what I want is when user go to index.php without logging in... the program must redirect the user to login page.. Is there a session kind of code in angularjs?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.