...

View Full Version : Cancel Previous Refresh request before new refresh



Jenny Dithe
04-13-2011, 05:50 AM
Hi,

I have the below code:


<script type="text/javascript">
function loadQuickMessageCheck(File,ID){

var xmlhttp;

if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
}
else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById(ID).innerHTML=xmlhttp.responseText;
eucalyptus = setInterval(function(){loadQuickMessageCheck(File,ID)},20000);
}
}

xmlhttp.open("POST",File,true);
xmlhttp.send();
}
</script>


But I am overloading the server and crashing it. I've googled the issue and have found people with similar problems who talk about the need to cancel the last refresh request before they send the next refresh.

I even found this nice piece of code which worked for someone else.



try{window.clearTimeout(tRefresh)} catch(err) {}
tRefresh = setInterval(setContext, varInterval*60*1000);
}


I am not sure if this is the solution that I am looking for but if it is all my attempts at applying this code has been a bit of a disaster.

DaveyErwin
04-13-2011, 06:07 AM
I'm wondering if you know the difference between setInterval and setTimeout? I'm almost sure you would be wanting to use
setTimeout .

Jenny Dithe
04-13-2011, 06:35 AM
Thank you. I needed reminding about that



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum