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 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? If so, how? If not, is there another way to do it?
+5
A:
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).
Rob Van Dam
2009-12-24 18:55:48
A:
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>
streetparade
2009-12-24 19:27:33
That requires the user to click each time to update it, though.
ceejayoz
2009-12-24 19:52:03
hmm.. this can be also done in a forever loop for(;;)
streetparade
2009-12-24 20:17:15