如何在另一个进程更新表时显示弹出消息

时间:2014-11-30 07:26:23

标签: php jquery ajax

在我的项目中,当我的项目表的记录被更改或由另一个进程更新时,我需要自动显示弹出消息。例如,当某人添加新记录时,应为每个看到系统的人显示弹出消息,即添加了新记录。

3 个答案:

答案 0 :(得分:3)

您需要使用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 : )
    });

答案 1 :(得分:0)

执行此操作的一种方法是在AJAX更新HTML DOM中的数据时添加alert()弹出窗口。

$.ajax{
  url: someCode.php,
  success: function(){
    // update the table in the HTML DOM
    alert('Table has been updated!');
  }
}

如果你想要一个花哨的弹出窗口,你也可以使用the jQuery UI dialog

答案 2 :(得分:0)

创建一个这样的隐藏div:

   <div class="popupwindow" style="display:hidden"> change has been made</div>

你可以将这个div看起来像一个灯箱或任何你想要的

如果您正在使用jquery ajax,请使用成功函数

   $(".popupwindow").fadeIn(400);

你也可以在一段时间后淡出 或者您可以使用警报方法而不是隐藏的div,这取决于您