在我的项目中,当我的项目表记录被另一个进程更改或更新时,我需要自动显示弹出消息。例如,当有人添加新记录时,应该为每个看到系统的人显示一条弹出消息,表明已添加新记录。
您将需要使用 ajax 轮询 - 非常简单的解决方案。它将每秒检查数据,并在内容更改时发出警报:)
使用 ajax 发送上次更新时间,并检查在此时间之后是否有新内容实际。
$.post( "test.php", { last_update: var_with_last_time })
.done(function( data ) {
alert( "Data Loaded: " + data );
// here check if the server returned something like {"changed":"true"}
if(value == true){
alert( "Data CHANGED");
//Here fire new update request to refresh content, or you could do this in the same ajax call
// You must change some php : )
});
一种方法
是在 AJAX 更新 HTML DOM 中的数据时添加一个alert()
弹出窗口。
$.ajax{
url: someCode.php,
success: function(){
// update the table in the HTML DOM
alert('Table has been updated!');
}
}
如果你想要一个花哨的弹出窗口,你也可以使用jQuery UI对话框。
创建一个隐藏的div,如下所示:
<div class="popupwindow" style="display:hidden"> change has been made</div>
您可以将此div 样式设置为看起来像灯箱或任何您想要的东西
如果你正在使用jQuery Ajax,在你的成功函数中
$(".popupwindow").fadeIn(400);
您也可以让它在一段时间后淡出或者您可以使用警报方法而不是隐藏的div,这取决于您