<script>
function polling() {
// 执行轮询操作 : 异步
var xmlHttp;
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttp.onreadystatechange = function(){
if(xmlHttp.status == 200 && xmlHttp.readyState == 4){
result = xmlHttp.responseText;
if (result == "true") {
window.location.href = 'welcome.php';
}
}
}
// 后台访问数据库
randnumber = document.getElementById("randnumber").value;
xmlHttp.open("GET", "polling.php?randnumber=" + randnumber, true);
xmlHttp.send();
}
// 每 1000ms 执行一次 polling()函数
setInterval("polling()", 1000);
</script>