I'm having an issue with a code that is meant to check if a page has loaded and then alert me with a status. However, the code doesn't seem to be working properly. I would really appreciate it if someone could take a look at it and point out where I went wrong. Looking forward to your response!
var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject(){
var xmlHttp;
if(window.ActiveXObject){
try{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
xmlHttp = false;
}
}else{
try{
xmlHttp = new XMLHttpRequest();
}catch(e){
xmlHttp = false;
}
}
if(!xmlHttp){
alert("Error");
}
else{
return xmlHttp;
}
}
function process(){
if(xmlHttp.readyState==0 || xmlHttp.readyState==4){
xmlHttp.open("GET", "djhgkjshgkjsd.com", true);
xmlHttp.onreadystatechange = handleServerResponse;
}
else{
setTimeout('process()', 1000);
}
}
function handleServerResponse(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
xmlResponse = xmlHttp.responseXML;
alert("Hi..."); // This is just to test where my code fails
}else{
alert('Something is wrong!');
}
}
}