I programmed a CMS that has a log of who has recently logged into the system. Presently, this data is fed into a jQuery UI tab via Ajax. I would like to put this information
PHP side, use json_encode().
Client side, use $.getJSON():
function refreshUsers(){
$.getJSON(url, postData, function (data, textStatus){
// Do something with the data
});
}
// Keep interval in a variable in case you want to cancel it later.
var refreshInterval = setInterval(refreshUsers, 30 * 1000);
With these 2, you should have a lot to get started with. More than this, you'd be asking us to work for you :)
The simplest way (whether its the best way is subjective - for the use case you've presented I'd say its fine) would be to do:
var updateInterval = setInterval(function() {
$('#whereIWantToDisplayIt').load('/thePathToThatScript.php');
},30*1000);
Every 30 seconds, this would load the output of your PHP script, and put that output into the element with ID = whereIWantToDisplayIt
I prefer Seb's answer though.