开发者

how to create a while in jquery for alwayes in browser

I would like to create a chat script, and check for check new replies.

I need to a while Once every 4 seconds checking new message in file db.php

Sample :

function while_check_seen()
{
    $(".replay").delay(4000).load("../db_pm开发者_运维技巧s.php?action=check");    
    while_check_seen()
}

This while worked, but used a lot of CPU!

Can anyone suggest a better way?


You can try this:

setInterval(function() {
    $(".replay").load("../db_pms.php?action=check");    
}, 4000);

https://developer.mozilla.org/en/window.setInterval


You can use a jQuery plug-in that will periodically poll a given URL and (optionally) update a page as necessary.

Such as here: http://plugins.jquery.com/plugin-tags/periodic-updater

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜