tags:

views:

50

answers:

2

Can anyone please tell me how to write a small div container in HTML that refreshes its contents from the data in mysql every 5 min.

This is similar to twitter updates in some webpages which show updates as and when tweeted.

Thanks.

+3  A: 

You can use the setInterval function to make AJAX calls:

setInterval(function() {
    $('#dynamicDiv').load('DynamicDivData.php');
}, 5 * 60 * 1000);    //300,000 milliseconds.

Where DynamicDivData.php connects to the database and returns the HTML to put in the <div>.

To avoid caching issues, you can append a random number in the querystring:

$('#dynamicDiv').load('DynamicDivData.php?NoCache=' + Math.random());
SLaks
+1 for the no cache tip.
zaf
A: 

With Jquery

$(document).ready(function () {
    $("#live").load("ajax.php");
    var refreshId = setInterval(function () {
        $("#live").load('ajax.php?randval=' + Math.random());
    }, 3000);
});

it calls ajax.php in first load and every 3 seconds to #live div.

Osman Üngür
This would be much more readable if it had newlines.
SLaks
ok i'd edited code
Osman Üngür