Well your isLoggedIn() function is starting an Ajax call, but that doesn’t mean it will get to complete it. Essentially I have a function that starts the call, and then separate functions that handle the possible return values. For instance:
function bounce() {
$e('enter').disabled=true;
var h = $e('horiz').value;
var v = $e('vert').value;
var g = $e('grav').value;
var e = $e('ela').value;
ptext("display","<img src=\\"images/loading.gif\\" alt=\\"loading..\\" />");
$.ajax({type: "POST", url: "php/bounce.php", data: "v=" + v + "&h=" + h + "&g=" + g + "&e=" + e, success: printHTML, error: handleError});
return;
}
function handleError (obj, input) {
ptext("display","Experiencing a server error");
return;
}
function printHTML(input) {
$e('display').innerHTML = '<img src="' + input + '" alt="' + input + '" class="animated"/>';
$e('enter').disabled = false;
return;
}
// Hide a given element
function hide(el) {
$e(el).style.display = "none";
return;
}
// Show a given element
function show(el) {
$e(el).style.display = "block";
return;
}
// Update the innerHTML for an element
function ptext(el, t) {
$e(el).innerHTML = t;
return;
}
function $e(el) {
return document.getElementById(el);
}
Here I’m using the jQuery JS library to handle the Ajax for me so I don’t have to learn what the various differences between the browsers are. So the $.ajax function handles the request back to the server, and you can see that two of the arguments for it are the name of a return function, and an error function (in case of a timeout or something similar).
Basically the script doesn’t just wait there for a reply from the server, it keeps moving along, so typically, an Ajax request should be the last line of a dummy function. Then once you have a return value from the server, you handle the return value in a separate function.
What this means for you is that you can’t access the return value in your isLoggedIn function, you need to handle that part of the logic (handling what happens with the user) in a different function.
Btw, this script is part of a script I wrote which takes some user entered values, and creates an animated Gif out of them using Php, and uses Ajax to send the information about the Gif to the server, then the server sends back the name of the image file it’s created, wrapped in an image HTML element.