Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load a part of page every 30 seconds [duplicate]

Possible Duplicate:
jQuery Ajax request every 30 seconds

I know we can load a part of page on some event. I also know we can load whole web page every specified time, but I wanted to know how to load a part of page every 30 seconds.

like image 417
Sapna Agrawal Avatar asked Dec 21 '22 19:12

Sapna Agrawal


1 Answers

function refreshPage() {
    $.ajax({
        url: 'ajax/test.html',
        dataType: 'html',
        success: function(data) {
            $('.result').html(data);
        },
        complete: function() {
            window.setTimeout(refreshPage, 30000);
        }
    });
}

window.setTimeout(refreshPage, 30000);

Using setTimeout has the advantage that if the connection hangs for some time you will not get tons of pending requests since a new one will only be sent after the previous one finished.

like image 68
ThiefMaster Avatar answered Dec 31 '22 03:12

ThiefMaster