My friend and I maintain a submission site with comments. We want to know if it is possible to have a constant AJAX connection. Basically, each submission has a comments section. My friend had a开发者_运维问答n 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? 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>
精彩评论