简体   繁体   中英

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. 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?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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