Hi there I am calling the following js function after xxx seconds to make a AJAX call to the server. User of this app is permitted to set the variable refresh interval time if he/she wants.
function startTimer(sessionId, jsPageRefreshInterval){
var xmlHttp;
param = “refreshInterval”;
// alert(param + ” = ” + refreshInterval + ” = ” + sessionId + ” = ” + jsPageRefreshInterval);
try{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}catch (e){
// Internet Explorer
try{
xmlHttp=new ActiveXObject(“Msxml2.XMLHTTP”);
}catch (e){
try{
xmlHttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}catch (e){
alert(“Your browser does not support AJAX!”);
return false;
}
}
}
xmlHttp.open(“GET”,”JobControllerUtilServlet?” + “sessionId=” + sessionId + “¶mChanged=true¶m=” + param + “&value=” + refreshInterval, true);
xmlHttp.setRequestHeader(“If-Modified-Since”, “Sat, 1 Jan 2000 00:00:00 GMT”);
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4 || xmlHttp.readyState==’complete’)
{
if (xmlHttp.status==200){
// alert(xmlHttp.status);
document.getElementById(‘theTable’).innerHTML = xmlHttp.responseText;
dkc=setTimeout(“startTimer(‘” + sessionId + “‘, ‘” + jsPageRefreshInterval + “‘);”, jsPageRefreshInterval);
// return true;
}
}
}
xmlHttp.send(null);
}
The problem is that the existing loop doesn’t stop. (As I have debugged it by alert() messages too). And the new assigned refresh inteval also start refreshing the page. Hence instead of only refreshing the page at the newly assigned interval, it start refreshing the page on diffrenet intervals. Can anyone please help me that what is the reason behind it. I feel that we need to stop the old refresh first and then start the new one. But don’t know how to do that. Would be very greatful if someone help me out.
regards