Really simple javascript function that does an AJAX call. When the function returns, it returns with a boolean value (not a string). Right now, for testing purposes, I have it set to always return 'true'. Problem is that I don't seem to be able to capture this value so that I can evaluate it. Here is the code:
function verifySession() {
var xmlhttp = new XMLHttpRequest();
var returnValue = xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
// this is wrong, but I don't know how to alter it for boolean values
session_verified = xmlhttp.responseText;
// this outputs as empty, even though the return value is true
console.log(session_verified);
if (!session_verified) {
console.log("false value returned");
return false;
} else {
console.log("true value returned");
return true;
}
}
}
xmlhttp.open("GET", "/scripts/session_verifier.php", false);
xmlhttp.send();
return returnValue;
}
session_verifier.php basically looks like this (again, grossly simplified for testing purposes):
<?php
return true;
?>
I've used this many times for functions that return strings, but this time I need it to return a boolean value. How can I capture its return value? Thanks!