Within my Javascript/AJAX function below, I am striving for a return of true or false:
function submitValidate() {
var xmlhttp;
xmlhttp = null;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
try { xmlhttp = new XMLHttpRequest();
}
catch (e){}
} else if (window.ActiveXObject) {
try { xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
}
catch (e){
try { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); // code for IE6, IE5
}
catch (e){}
}
}
if (xmlhttp) {
xmlhttp.open("GET","registerTest.php",true);
xmlhttp.send();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
if (xmlhttp.responseText==="true") {
return true;
}
} // if xmlhttp.readyState && xmlhttp.status
}// xmlhttp.onreadystatechange
}// if
return false;
} //submitValidate()
The challenge arises when attempting to directly 'return true;' within the onreadystatechange function as shown here -
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
if (xmlhttp.responseText==="true") {
return true;
}
} // if xmlhttp.readyState && xmlhttp.status
}// xmlhttp.onreadystatechange
.. If there's a method to have submitValidate() return true in that scenario, kindly share.
Your feedback is greatly appreciated.