jquery kind of cron job :P
// CHECK NEW MESSAGES (CRON)
(function checkNewMessages() {
$.ajax({
url: "<?=site_url('message/process')?>",
type: 'post',
data: {'job': 'checkNewMessages'},
success: function(data) {
//console.info(data);
var data = $.parseJSON(data);
//console.info(data);
if(data.info == 'success')
{
//alert(data.result);
if($('#counter').length > 0)
{
$('#counter').html(parseInt(data.result));
}
}
else
{
if($('#counter').length > 0)
{
$('#counter').html('');
}
}
},
complete: function() {
// Schedule the next request when the current one's complete
setTimeout(checkNewMessages, 5000);
}
});
})();