我正在尝试使用setInterval
来模拟自制推送通知,但不知道如何执行此操作。 ajax请求在显示消息时效果很好。这不是问题。我正在尝试在section style='notification'
中显示单独的通知。
Ajax代码段
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>
答案 0 :(得分:2)
Javascript的.load()方法有一个可选参数,它是在加载完成后要执行的函数。它看起来像这样:
$('#displayMessage').load('log.php', function(){
$('#notification').show();
});