简体   繁体   English

实时AJAX内容

[英]Live AJAX content

My friend and I maintain a submission site with comments. 我和我的朋友维护一个带有评论的提交站点。 We want to know if it is possible to have a constant AJAX connection. 我们想知道是否可以保持恒定的AJAX连接。 Basically, each submission has a comments section. 基本上,每个提交都有一个评论部分。 My friend had an idea of having an alert appear on the page everytime a new comment came in. So, would it be possible to keep up a constant link between the AJAX object and a PHP script that queries the comment database? 我的朋友有个想法,每当有新注释出现时,页面上就会出现警报。那么,是否有可能在AJAX对象和查询注释数据库的PHP脚本之间保持恒定的链接? If so, how? 如果是这样,怎么办? If not, is there another way to do it? 如果没有,还有另一种方法吗?

Sounds like you are describing Comet . 听起来您在描述彗星

Alternatively, most sites that do that kind of thing just make a query to the server every so often asking if anything new has been posted (need to make sure you pass in a timestamp of the last time you checked). 另外,大多数做这种事情的站点只会经常询问服务器是否发过新消息(需要确保您输入了上次检查的时间戳)。

this could be an option this worked for me. 这可能是对我有用的选择。

<a href="javascript:;" onclick="$('#mycomments').load('http://s.bla/rpc.php?qry=11',
function(){$('#mycomments').show('slow');});">Comments</a>
<div id="mycomments" style="display:none;">
Comments
</div>

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

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