Need Help Can anyone please suggest me How can i pass token_value to my all other function. token_value is the sucs response value. If i call the login() function it requires me to pass username and password. so I cant call the function. But I need to pass the token_value that generated once i login.
$("#submit_login").click(login);
var token_value = "";
function login(){
var login = {
username: $("#username > input").val(),
password: $("#password > input").val()
};
$.ajax({
type: "POST",
url: "http://localhost:9000/login",
contentType: "application/json",
data: JSON.stringify(login)
})
.done(function(res){
token_value = res.token;
$("#test2").append(token_value);
alert("You are logged in successfully");
})
.fail(function(error){
console.log(error);
alert ("could not sign in");
});
return token_value;
};