我有一些AJAX显示使用setInterval()
获取脚本当前进度的进度条。我的问题是,当进度达到100%时,我似乎无法杀死它。我不确定这是否与范围有关,但我的处理程序是全局的,所以我无法弄清楚它为什么不起作用。以下是我的:Javascript - 清除间隔和设置间隔范围
function showLog(){
document.getElementById('log').style.display = "block";
clearInterval(inth);
return false;
}
function startAjax(){
var inth = setInterval(function(){
if (window.XMLHttpRequest){ xmlhttpp=new XMLHttpRequest();}else{ xmlhttpp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttpp.onreadystatechange=function(){
if(xmlhttpp.readyState==4 && xmlhttpp.status==200){
document.getElementById("sbar").innerHTML=xmlhttpp.responseText;
}
}
xmlhttpp.open("POST","scrape.php",true);
xmlhttpp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
var sitelist = document.getElementById('website').value;
var par = "website="+sitelist;
xmlhttpp.send(par);
}, 5000);
return false;
}
为什么clearInterval不起作用?我究竟做错了什么?
哪里的代码决定什么时候达到100%? – 2013-04-24 06:48:42
@Jack一旦进度达到100%,就会在'scrape.php'中打印。最初我尝试了一个'if(xmlhttpp.responseText ==“100%”)类型的东西,但是这样做效果不好。 – 2013-04-24 07:01:17