setInterval()
スクリプトの現在の進行状況を取得するために使用する進行状況バーを表示する AJAX があります。私の問題は、進行状況が 100% に達したときにそれを殺すことができないように見えることです。これがスコープに関係しているかどうかはわかりませんが、私のハンドラーはグローバルであるため、なぜ機能しないのかわかりません。ここに私が持っているものがあります:
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 が機能しないのはなぜですか? 私は何を間違っていますか?