0
A
回答
2
我不認爲你會發現,具體的教程,但你只需要學習AJAX然後進行AJAX使用JavaScript的setInterval方法調用每兩分鐘。
編輯
咩,我已經夠無聊寫這個例子。這沒有經過測試,但我不認爲它有錯誤。
<html>
<head>
<script type="text/JavaScript">
window.onload = function()
{
// call your AJAX function every 2 minutes (120000 milliseconds)
setInterval("getRecords()", 120000);
};
function getRecords()
{
// create the AJAX variable
var xmlhttp;
if (window.XMLHttpRequest)
xmlhttp = new XMLHttpRequest();
else
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
// set up the response function
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
/*
Your code goes here. 'xmlhttp.responseText' has the output from getRecords.php
*/
document.getElementById("txaRecords").innerHTML = xmlhttp.responseText;
}
}
// make the AJAX call
xmlhttp.open("GET", "getRecords.php", true);
xmlhttp.send();
}
</script>
</head>
<body>
<textarea id="txaRecords"></textArea>
</body>
</html>
1
這是我爲這個確切目的編寫的一些代碼。酌情適應。
AJAX代碼:
function timer()
{
var t=setTimeout("check()",2000);
// At an appropriate interval
}
function check(){
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
if (xmlhttp.responseText!=""){
var output = xmlhttp.responseText;
// Do what you need to do with this variable
}
}
}
xmlhttp.open("GET","backend.php",true);
// Set file name as appropriate.
xmlhttp.send();
timer();
}
PHP代碼:
<?php
// This assumes you have already done mysql_connect() somewhere.
// Replace as appropriate
$query = "SELECT * FROM table_name";
// Perform the query
$result = mysql_query($query);
// Get the results in an array
while($row = mysql_fetch_array($result)) {
// Echo the message in an appropriate format.
echo "<br />" . $row['column_name'];
}
?>
記住要啓動的JS功能之一爲您加載頁面:
<body onload="timer()">
相關問題
- 1. SQL查詢顯示記錄
- 2. SQL查詢顯示來自同一個表的多個記錄?
- 3. 使用SQL查詢顯示多個值
- 4. SQL查詢得到計數和行與多個記錄
- 5. sql查詢不顯示重複記錄
- 6. 顯示4x記錄的SQL查詢
- 7. SQL查詢,不顯示所有記錄
- 8. SQL查詢顯示唯一記錄
- 9. 顯示SQL查詢的重複記錄
- 10. 查詢多次顯示每條記錄
- 11. SQL查詢多記錄
- 12. 查詢不顯示記錄
- 13. SQL:查詢基於多個記錄
- 14. 多個表/記錄的SQL查詢
- 15. SQL查詢返回多個記錄
- 16. SQL查詢的結果顯示使用的記錄設置
- 17. 如何使用綁定值顯示DMS SQL查詢記錄?
- 18. SQL查詢來顯示計時錶
- 19. SQL查詢顯示良好的記錄以及空記錄
- 20. 如何停止一些記錄顯示多次在SQL查詢
- 21. 使用SQL使用多個查詢的多個SQL計數
- 22. 如何查詢多個相似記錄中只顯示一條記錄的查詢? [Microsoft SQL]
- 23. MySQL查詢:顯示多個記錄組的許多組的計數
- 24. 轉換多個記錄單記錄使用SQL查詢10個LAC數據
- 25. 在json中顯示多條記錄使用php mysql查詢
- 26. sql數據讀取器顯示一個小於sql查詢輸出的記錄
- 27. SQL查詢與多個小計
- 28. 使用計數時SQL查詢不顯示所有結果
- 29. 從一個sql查詢獲取記錄並在另一個查詢中使用
- 30. Upsert查詢多個記錄
非常感謝你。有用! – jaypabs 2012-02-23 15:53:04
@ user1034801:如果有效,請將其標記爲您接受的答案。謝謝! – Travesty3 2012-02-23 17:07:03
我不能投票。它說:投票需要15點聲望。 – jaypabs 2012-02-23 23:29:52