現在,我建立一個排隊系統,我有一個像下面的AJAX功能:我婉改變setTimeout的值時,有數據變化
<script type="text/javascript" >
(function worker() {
$.ajax({
url: 'http://localhost/queue/queue_list.php',
success: function(data) {
$('#result').html(data);
},
complete: function() {
// Schedule the next request when the current one's complete
setTimeout(worker, 3000);
}
});
})();
<script>
<div id="result"></div>
在功能上,系統會刷新數據每3秒更新一次表格視圖,如果有數據更改。
我想要的是,當queue_list.php上有數據變化時,setTimeout將變爲20秒(播放語音呼叫),但如果沒有數據變化,setTimeout值將不會改變。 如何更改setTimeout值?
queue_list.php
<?php
function nomornya($loket,$huruf){
include"database.php";
$sqlnyah="select count(id) as ceknya from panggilan_antrian where loket='$loket' and huruf='$huruf'";
$sqlnyah2="select nomor from panggilan_antrian where loket='$loket' and huruf='$huruf'";
$querynyah=mysqli_query($sqlnyah);
$angkan=mysqli_fetch_assoc($querynyah);
$angkany=$angkan[ceknya];
if($angkany!=0){
$querynyah2=mysqli_query($sqlnyah2);
$angkan2=mysqli_fetch_assoc($querynyah2);
$angkanya=$angkan2[nomor];
}else{
$angkanya="0";
}
echo $angkanya;
}
?>
<style>
table,tr,td{
font-size:1.7em;
}
</style>
<table style="width:100%;text-align:center;">
<tr style="background:#000000; color:#ffffff;">
<td>COUNTER</td>
<td>NOMOR</td>
</tr>
<tr style="background:#b1c2f3">
<td>1</td>
<td><?php nomornya(1,null); ?></td>
</tr>
<tr style="background:#d2f3b1">
<td>2A</td>
<td><?php nomornya(2,A); ?></td>
</tr>
<tr style="background:#b1c2f3">
<td>2B</td>
<td><?php nomornya(2,B); ?></td>
</tr>
<tr style="background:#d2f3b1">
<td>2C</td>
<td><?php nomornya(2,C); ?></td>
</tr>
<tr style="background:#b1c2f3">
<td>3</td>
<td><?php nomornya(3,null); ?></td>
</tr>
<tr style="background:#d2f3b1">
<td>4</td>
<td><?php nomornya(4,null); ?></td>
</tr>
</table>
我不知道如何使用它,我如何檢查數據是否更新,然後設置新的超時? – Gumilar