我和我的朋友有一个提交评论的网站,我们想知道是否可能有一个恒定的Ajax连接。基本上,每个提交都有一个注释部分。我的朋友有一个想法,就是每当有新评论出现时,页面上就会出现警报。那么,在Ajax对象和查询注释数据库的PHP脚本之间是否可以保持一个恒定的链接呢?如果是,怎么做?如果没有,还有别的办法吗?
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>