View Full Version : Cancel Previous Refresh request before new refresh

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

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");

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


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.

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