0
我想讓Ajaz每5秒使用一個php文件從數據庫中獲取數據,並且過程繼續。它似乎在Firefox中工作很好,但不會在IE中更新。Ajax settimeout從php/mysql中讀取狀態
任何人都可以幫助使這個平臺獨立?
阿賈克斯/ jQuery代碼
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的空div,我有onclick事件觸發startprogress()功能。
任何人都可以幫忙嗎?
非常感謝。
如果你想要活的東西,你應該檢查像websocket /節點。另外,我認爲你應該使用setInterval()來代替。 – malletjo
切換到setInterval。很好的工作,但腳本完成後才停止,直到刷新瀏覽器。雖然它適用於我的目的。 – Reg