drn9573 2014-07-17 10:05
浏览 39
已采纳

仅在有人提交新邮件时加载数据

So I created really simple chatbox in php. It works very good, but I had to set up script that is nonstop loading data from database to the chat window (not probably the most efficient way, that's why I am asking):

    <script type='text/javascript'>
    $('#chatbox').html('Loading...');
    $(document).ready(function() {
    setInterval(function(){loop()}, 0);
    function loop(){
     $('#chatbox').load('/chatbox.php');
    }

}); 
    </script>

And in chatbox.php:

include '/classes/class.chatbox.php';
$chat = new Chat();
$chatboxMsg = $chat->getNewMessages();
echo $chatboxMsg;

But this isn't the problem. My question is, how can I load the data (=refresh chat) for ALL users that have opened chat window, only when someone post new message (=insert new row to the db), without running script that is checking something every second?

  • 写回答

3条回答 默认 最新

查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效