Can you help me figure out why this JavaScript function keeps returning 'undefined'? I really need it to return either true or false. I've included my code below:
function Ajax() {
var XML;
if(window.XMLHttpRequest)
XML=new XMLHttpRequest();
else
XML=new ActiveXObject("Microsoft.XMLHTTP");
XML.onreadystatechange=function() {
if(XML.readyState == 4 && XML.status == 200) {
if(XML.responseText == '1') {
return true;
} else {
return false;
}
}
XML.open("POST","p.php", false);
XML.setRequestHeader("Content-type","application/x-www-form-urlencoded");
XML.send("user=f");
}
I'm truly baffled as to why.