How to display a pop up notification to the user using jquery?

后端 未结 4 507
遥遥无期
遥遥无期 2021-01-31 19:02

I am developing an application which requires that user must be notified about some background events i.e. invitation from other user, reminder time out etc.

Whenever t

4条回答
  •  庸人自扰
    2021-01-31 19:48

    Using code from @Anu's suggestion - my fiddle, you can simply add a poll

    $(document).ready(function() {
      $(".dismiss").click(function(){$("#notification").fadeOut("slow");});
    
      setInterval(function() {
        $.get("ping.jsp?userid=<%= userID %>",function(message) {
          if (message) $("#notification").fadeIn("slow").html(message);
        });
       ,10000);
    })
    

    the message could include a timestamp to see if you had notified earlier instead of sending an empty message if no notificati9on is needed

    Alternatives: Long poll or Comet

提交回复
热议问题