dongpo5207 2009-12-26 06:40
浏览 17
已采纳

数据库更新时的警报消息

I am creating a Chat application in php.

AIM: when a user1 invites user2, user2 want to get a alert or popup message that user1 has invites him.

What i have done is -

When user1 invites, the message is stored in database. In user side i used to check whether Database is updated or not. If database is update i used to show alert. This i done on php and javascript but not working all time.

Is this a good method? Any other method?

  • 写回答

4条回答 默认 最新

  • drne47241 2009-12-26 07:48
    关注

    All the clients can use jquery and send following request periodically:

    function checkIfIAmInvited()
    {
         jQuery.ajax({
           type: "POST",
           url: "some.php",
           data: "name=currentUser&",
           success: function(msg){
             if(msg.indexOf('uninvited') !== -1 )
             {
                alert( "You have been invited by " + msg );
                //Method to do stuff once I am invited
                iAmInvitedMethod();
             }
         });
    }
    

    To call above code periodically you can use following code in jquery/javascript. This would be making periodic calls and getting the response back to you. As soon as the response come without containing "uninvited" string it gives an alert and also calls the post method function.

    This can be repeatedly called with following code.

    window.setInterval("checkIfIAmInvited()", 5000);
    

    This will check every 5 seconds if there are any invitations. Alternatively for a more better control jquery plugins like Timer can be used to execute something repeatedly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 深度学习残差模块模型
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)