我想模擬使用setInterval
自制推送通知,但不知道如何做到這一點。 ajax請求在顯示消息時工作得很好。這不是問題。我試圖在section style='notification'
中顯示單獨的通知。setInterval如果Ajax返回數據顯示div
阿賈克斯片斷
setInterval(function(){
$.ajaxSetup({
cache:false,
type: "GET",
url: "log.php",
data: data,
});
$('#displayMessage').load('log.php');
//display div notification if return data
//document.getElementById('notification').style.display = 'block';
}, 3000);
標記
<section style='display:none;' id='notification' class="notif notif-notice alert alert-dismissable">
<h6 class="notif-title">Congratulations!
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
</h6>
<p>You have just received a new message</p>
</section>
您的'load'調用正在使用id爲'displayMessage'的元素進行操作。但是在你的標記中沒有這個id的元素。你期待這件事做什麼? – RJM
@RJM:試圖顯示板塊通知 –
@RJM:爲了弄清楚事情我更新了我的問題。這個問題與displayMessage無關。它效果很好。我只是試圖顯示一個單獨的獨立分區。 –