I have this Javascript/AJAX function:
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()
I would like for submitValidate() to return true or false.
However I have come to realize that I cannot just 'return true;' inside the onreadystatechange function as I did 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 I want submitValidate() to return true in that case.
Can somebody please tell me how I can get submitValidate() to return true if the onreadystatechange function returns true?
Thanks in advance.