我有这个脚本和以下站点。看起来很奇怪,脚本甚至没有触发第一个警报。如果我用警报替换“update_table”函数,它会显示警报。
<head>
<script src="signals.js" type="text/javascript">
update_table();</script>
</head>
<body>
现在这是来自 signals.js:
function update_table()
{
alert("h");
var old_table = document.getElementById('signals').innerHTML;
alert("h");
var req = new XMLHttpRequest();
alert("h");
req.onreadystatechange = function(){
if(req.status == 200)
{
if(req.readyState == 4)
{
var new_table = req.responseText;
if(old_table != new_table)
{
//play sound
alert("Sound!");
}
alert("Refresh!");
setTimeout(update_table(), 5000);
}
}
}
var link = "table.php?refresh=true";
alert("h");
req.open("GET", link, true);
req.send();
alert("h");
}