如何修复Jquery轮询继续无限?

I want to get a page refreshed after every 3 minutes. It contains a table where each row represents a detail of a post.

Users can reply to the post, and that notification will be shown as a red bubble with 1(no. of unread message).

I am trying to use a simple Jquery polling technique to achieve this. However, I am doing something wrong and it is not working as I expect.

I have a html which is like this:

<?php
for($posts as $row)
{
if($entity == 'post')
{ $id = $row['id'];?>
    <a href="javascript:void(0)" onclick="push_notification('<?php echo $entity;?>','<?php echo $id;?>')" title="Push Notification">
        <img src="<?php echo(base_url())?>assets/images/icon/arrow_right.png" width="22" height="22" border="0" alt="Push Notification" onload="chat_review('<?php echo $id;?>')"/></a>
    <a href="<?php echo base_url();?>admin/<?php echo $entity;?>/<?php echo $entity;?>_chat/<?php echo $id;?>" title="Chat">
        <div class="ch_comment" id="chatReviewDiv_<?php echo $id;?>"><?php if($row['chat_count']>0){?><div class="notify"><?php echo $row['chat_count'];?></div><?php }?></div>
    </a>
<?php
} }?>

Now here is the onload function:

function chat_review(post_id)
{
    $.post('<?php echo base_url();?>ajax-function', 
        {'data':'chat',
        'id': post_id,
        'action': 'select'},
        function(data) {
            alert(data.id);
            if(data.chatCount > 0)
            {
                $("#chatReviewDiv_"+data.id).clear();
                $("#chatReviewDiv_"+data.id).append("<div class='notify'>"+data.chatCount+"</div>");
            }  // process results here
            setTimeout(chat_review(data.id),50000);
    }, 'json');
}

However, this is causing the overflow of the firbug limit. Firebug Limit Reached

What is causing this abrupt behavior? How can I solve this? That list should call the chat_review function 20 times(for 20 posts). Then after 3 minutes, again the chat_review will be called for each 20 posts. But currently, the chat_review is being called infinitely.

You are using setTimeout in wrong way. You call chat_review immediately and it calls itself infinitely. You should pass reference of your function instead, or use extra function wrapper:

function chat_review(post_id)
{
    $.post('<?php echo base_url();?>ajax-function', 
        {'data':'chat',
        'id': post_id,
        'action': 'select'},
        function(data) {
            alert(data.id);
            if(data.chatCount > 0)
            {
                $("#chatReviewDiv_"+data.id).clear();
                $("#chatReviewDiv_"+data.id).append("<div class='notify'>"+data.chatCount+"</div>");
            }  // process results here
            setTimeout(function(){
                chat_review(data.id)
            },50000);
    }, 'json');
}

Using with .bind

function chat_review(post_id)
{
    $.post('<?php echo base_url();?>ajax-function', 
        {'data':'chat',
        'id': post_id,
        'action': 'select'},
        function(data) {
            alert(data.id);
            if(data.chatCount > 0)
            {
                $("#chatReviewDiv_"+data.id).clear();
                $("#chatReviewDiv_"+data.id).append("<div class='notify'>"+data.chatCount+"</div>");
            }  // process results here
            setTimeout(chat_review.bind('', data.id),50000);
    }, 'json');
}