[ js ] setTimeout更新頁面
正在寫一個投票系統,投票到開票時間設定之後,介面會根據時間自動轉換
js的部分
function checkstatus()
{
var xmlhttp;
if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
if( document.getElementById(mode).innerHTML != xmlhttp.responseText )
{
switch(xmlhttp.responseText)
{
case prepared:
document.location.href="prepared.php";
break;
case voting:
document.location.href="voting.php";
break;
case completed:
document.location.href="completed.php";
break;
}
}
}
xmlhttp.open("GET","check_status.php",true);
xmlhttp.send();
setTimeout(function(){checkstatus();},3000);
}
然後html用<script>check_status()</script>來呼叫
可是每次都執行一次就停止了
而且我在function內放alert也沒有反應,完全不知道程式跑到哪
請求一下協助
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 68.33.32.85
→
10/15 21:06, , 1F
10/15 21:06, 1F
貼錯了,因為我後來改了function名稱
<script>checkstatus()</script>才對
→
10/15 22:25, , 2F
10/15 22:25, 2F
試過這種,也一樣
※ 編輯: LordCHTsai 來自: 68.33.32.85 (10/16 01:56)
→
10/16 22:16, , 3F
10/16 22:16, 3F
→
10/16 22:17, , 4F
10/16 22:17, 4F
討論串 (同標題文章)