how can i trigger Jquery ajax call after the every 24 hours?
setInterval(function() {
$.post('get_sales.php', function(data) {
$('#updates_contents').html(data);
});
}, 5000);
If you want to stick with jQuery and PHP, you can do the following:
//var intervalTime = 24 * 60 * 60 * 1000; //refresh every 1 day
var intervalTime = 1 * 60 * 60 * 1000; //refresh every 1 hour
//the format is HOUR * MINUTE * SECONDS * MILI-SECOND.
function refresher() {
$.post('get_sales.php', function(data) {
$('#updates_contents').html(data);
});
}
var timerID;
function start() {
//you might want to refresh the content when the widget first loads then uncomment the following line
//refresher();
//and then set interval to refresh it later on
timerID = setInterval("refresher", intervalTime );
}
//if something went wrong, user can click on refresh button which can call this function
function refreshBtnClick() {
clearTimeout(timerID );
start();
}
start();
Remember to add a button to manually refresh the content suppose in case, automation failed. 1 hour refresh time will give you better results. Remember A. Wolff's comment about memory leaks.
If you are working on android TV app, you might just want to look at:
https://developer.android.com/reference/android/app/job/JobScheduler.html
Setting up a JS timer in browser and keep running your app 24/7 waiting for the timeout to occur is not practical.
Instead you can find a work around, like creating a scheduler class which refresh the content every 24 hours and stores it locally, which your browser just refresh the content from local db or file.