0
簡單地說,我有一個菜單欄,上面有由CSS製作的動畫通知標誌,並由SPAN類在HTML上實現。這個徽章應該顯示新消息的數量並且如果該計數爲0則消失。我需要每隔1秒檢查一次,但沒有運氣。Ajax定時更新問題
我的JS:
<script type="text/javascript">
function removeAnimation(){
setTimeout(function() {
$('.bubble').removeClass('animating')
}, 200);
}
setInterval(function() {
$.ajax({
type: 'GET',
url: 'models/bubble.php',
data: 'html',
success: function(response){
document.getElementById("bub").innerHTML=response;
document.getElementById("bub").className = "bubble";
}
error: function(response) {
document.getElementById("bub").className = "hidden";
});
}
}, 1000);
</script>
我的PHP(工作和測試):
<?php
require_once("db.php");
$receiver = $this_user
$isnew = 1;
$stmt = $mysqli->stmt_init();
if ($stmt->prepare("SELECT * FROM messenger
WHERE receiver = ? AND isnew = ? ORDER BY timestamp")) {
$stmt->bind_param("si", $receiver,$isnew);
$stmt->execute();
$stmt->store_result();
$ttlrows = $stmt->num_rows;
$stmt->close();
}
echo $ttlrows;
?>
任何幫助嗎?
的延遲之後會調用該函數只有一次什麼問題 –
它不讀取PHP的輸出,在舊版本的我的代碼它只讀取一次輸出。 –