从php/mysql读取状态的Ajax设置超时
我正试图让Ajaz每隔5秒使用一个php文件从mysql中提取数据,这个过程将继续。它在firefox中似乎工作得很好,但在IE中不会更新 有人能帮助使这个平台独立吗 Ajax/Jquery代码从php/mysql读取状态的Ajax设置超时,php,jquery,mysql,ajax,Php,Jquery,Mysql,Ajax,我正试图让Ajaz每隔5秒使用一个php文件从mysql中提取数据,这个过程将继续。它在firefox中似乎工作得很好,但在IE中不会更新 有人能帮助使这个平台独立吗 Ajax/Jquery代码 function startprogress() { $.get("status.php"); setTimeout('updateStatus()', 500); } function updateStatus() { $("#progress").load("status.
function startprogress() {
$.get("status.php");
setTimeout('updateStatus()', 500);
}
function updateStatus() {
$("#progress").load("status.php");
setTimeout('updateStatus()', 500);
}
PHP文件
mysql_connect("localhost","root","password") or
die("Could not connect: " . mysql_error());
mysql_select_db("table");
$sql="SELECT current, total FROM status WHERE id = 1";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo "Completed: " . $row['current'] ." of " . $row['total'];
}
然后在HTML文件中有一个id为progress的空div,其中有onClick事件来触发startprogress()函数
有人能帮忙吗
非常感谢。使用setInterval时,您应该执行以下操作:
var id = setInterval(function() {
// Do something each interval
}, 1000);
clearInterval(id); // When you want to clear it
一些例子和。如果你想要活生生的东西,你应该检查像websocket/node这样的东西。另外,我认为应该改用setInterval()。切换到setInterval。工作得很好,但在我刷新浏览器之前,脚本完成时不会停止。不过,这对我来说很有用。