What I'm trying to do is create a object that will handle my ajax calls, I need to repeatedly refresh a few pages over and over again, and create a object for each page is the only way I can think of to do that, and still have the ajax code asynchronous. But whenever I test this nothing is happening and I don't know why.
Here is my code
function PageLoader(url,id,repeatTime){
this.id = id;
this.url = url;
this.repeatTime = repeatTime;
this.start = function(){
var time = Date.now();
var xml = new XMLHttpRequest();
xml.open("GET",this.url,true);
xml.onreadystatechange = function(){
if(xml.readyState === 4){
document.getElementById(this.id).innerHTML = xml.responseText+" <small>("+(Date.now()-time)+")</small>";
if(this.repeatTime > 0){
setTimeout(this.start,this.repeatTime);
}
}
}
xml.send(null);
}
this.stop = function(){
this.repeatTime = -1;
}
}
And here is how I try to run it.
var infoAjax = new PageLoader('../modules/userinfo.php','StatusInfo',1000);
//Load everything automaticly
window.onload = function(){
infoAjax.start();
}