I have a small problem, I want to check if a user is logged in via AJAX POST to a PHP and then run the rest of the function, unfortunately the rest of the function is being ran without waiting for the AJAX to finish.. so that's bad news
function checkLogin() {
dat = 'chl=1&x='+Math.random();
$.ajax({
url: "/action.php",
type: "POST",
data: dat,
success: function(data) {
if (data)
return data;
return 0;
},
error: function(data) {
console.log('err'+data);
return;
}
});
}
function anotherFunction() {
logged = checkLogin(); // is the user logged in?
if (logged) {
// do other stuff
console.log('Logged in');
} else {
console.log('Not logged in..');
}
}
So this is my problem, it says logged is undefined.. Is there any solution to this, besides using setTimeout, something more "natural" in terms of time of wait?