【发布时间】:2019-09-11 11:12:57
【问题描述】:
我已经使用 setTimeout 函数重新加载我的通知下拉菜单,现在它运行良好,但是我的通知下拉菜单在重新加载时闪烁,请提供任何解决方案来停止闪烁。
这里附上我已经用过的。
$(document).ready(function(){
notification();
});
function notification()
{
setTimeout(function()
{
$('#notification_ico').load('<?php echo base_url();?>/Filemanagement/noti_refresh');
notification();
}, 3000);
}
function abc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("notification_ico").innerHTML = this.responseText;
}
};
xhttp.open("GET", "<?php echo base_url();?>/Filemanagement/noti_refresh", true);
xhttp.send();
}
我的页面不工作
【问题讨论】:
-
您在超时内重新加载后再次调用 notification() 函数,这导致通知函数一次又一次的递归调用并导致闪烁
-
我需要显示最近的通知,这就是为什么我在 setTimeout 函数中调用通知函数,所以它每 3 秒调用一次通知函数
-
你应该使用
setInterval而不是setTimeout
标签: javascript jquery html codeigniter