I'm making a post request to my web service and when it is successful i'm trying to delete a token I've previously put in local storage like this:
$http.post("MyService/MyAction").success(function (res) {
if (res == true) {
window.localStorage.removeItem(myToken);
//window.localStorage.getItem(myToken) returns null in here.
window.location = baseURL + 'Login.aspx';
}
}).error(function () {
//some stuff
});
and right after that I'm redirecting to Login page on the site. now when i check the local storage if the tokens deleted right after window.localStorage.removeItem(myToken)
, I see that it's deleted as window.localStorage.getItem(myToken)
returns null.
But after I redirect with window.location = baseURL + 'Login.aspx'
and check for the tokens with window.localStorage.getItem(myToken)
in the Login.aspx page the token is there and not deleted.
In Login.aspx
window.localStorage.getItem(myToken)
//in here the token is returned where it's suppose to be deleted.
At first I thought I'm adding the token again in somewhere between the redirection to Login.aspx, but when i use $.ajax to send the request and delete token it works. So is there something about angularjs that $http is not doing what I can do with $.ajax.