开发者

jQuery Timer plugin only runs once instead of each X seconds

I'm using jQuery and the jQuery Timers plugin: http://plugins.jquery.com/files/jquery.timers-1.2.js.txt

What I want to do is post data to a php script every 3 seconds. The script checks if there are new messages and if there are it will return them. I'm having a problem with the timer. Right now, it only runs the function once, after three seconds. After it has run one time, it doesn't run anymore.

$(function() {
$('.check'开发者_JS百科).everyTime(3000, function() {

var ID = $(this).attr("id");
    if(ID) {
        $("#check"+ID).html('<img src="img/loader.gif" />');
    $.ajax({
        type: "POST",
        url: "<?php echo $base;?>ajax_check_new.php",
        data: "latestmsg="+ ID, 
        cache: false,

        success: function(html){
            $("ol#msg").prepend(html);
            $("#check"+ID).remove();
        }
    });
}

  });
});

Any suggestions?

Thanks in advance!!


Is there a reason you are using jQuery Timers for this instead of setInterval?

EDIT:

$(function() {
    setInterval(function() {
        var ID = $('.check').attr("id");
            if(ID) {
                $("#check"+ID).html('<img src="img/loader.gif" />');
                $.ajax({
                    type: "POST",
                    url: "<?php echo $base;?>ajax_check_new.php",
                    data: "latestmsg="+ ID, 
                    cache: false,

                    success: function(html){
                        $("ol#msg").prepend(html);
                        $("#check"+ID).remove();
                    }
                });
            }
    }, 3000);
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜