I am attempting to refresh a table i have as the variables in there are constantly updated and i want to re-update those variable every few seconds. I have already done up c
I think setInterval with jQuery.load is the one you're looking for
var table = $("#tableID");
// refresh every 5 seconds
var refresher = setInterval(function() {
table.load("/path/to/js.php");
}, 5000);
Or shorten it up with
var refresher = setInterval(table.load.bind(table, "/path/to/data"), 5000);
If you'd ever like to stop refreshing the data, (e.g.,) say the user leaves the page open for a long time
// stop refreshing after 30 minutes
setTimeout(function() {
clearTimeout(refresher);
}, 1800000);
If your data load takes a while, you might want to only refresh X seconds after the data is loaded. You could do that like this using setTimeout
var table = $("#tableID");
var refresh = function() {
table.load("/path/to/js.php", function() {
setTimeout(refresh, 5000);
});
};
refresh();