繁体   English   中英

致力于php / ajax聊天系统

[英]Working on php/ajax chat system

我一直在研究ajax / php聊天系统,用户显然可以互相聊天。 我担心服务器负载,它最初编程的方式是每x秒自动刷新div(聊天框)它只是这是用户活动,因为我超时他们的不活动。 如果它们在10分钟左右保持不活动状态,它们将显示为空闲状态,系统将停止刷新。 然后我查看了使用HTML5的服务器发送事件,但效果很好,但并非所有浏览器都能使用它。

有没有人有更好的解决方案或现在div刷新好吗? 希望有人能帮助谢谢!

 // jQuery Document $(document).ready(function(){ }); //jQuery Document $(document).ready(function(){ //If user wants to end session $("#exit").click(function(){ var exit = confirm("Are you sure you want to end the session?"); if(exit==true){window.location = 'index.php?logout=true';} }); }); //If user submits the form $("#submitmsg").click(function(){ var clientmsg = $("#usermsg").val(); $.post("post.php", {text: clientmsg}); $("#usermsg").attr("value", ""); loadLog; return false; }); function loadLog(){ var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20; //Scroll height before the request $.ajax({ url: "log.html", cache: false, success: function(html){ $("#chatbox").html(html); //Insert chat log into the #chatbox div //Auto-scroll var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20; //Scroll height after the request if(newscrollHeight > oldscrollHeight){ $("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div } }, }); } setInterval (loadLog, 1000); </script> 

考虑使用COMET,或者查看Ajax Push Engine: Link

使用COMET的聊天系统示例: 链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM