Reputation: 3712
My page has a div where the content is written by a PHP script.
<div id="feastsaint"> <!-- Feast or Saint of the day -->
<?php
if(isset($_COOKIE["datetoday"])) {
echo $_COOKIE["datetoday"];
}
if(isset($_COOKIE["month"]) and isset($_COOKIE["day"]) and isset($_COOKIE["year"])) {
$showfeast = file_get_contents('http://feed.evangelizo.org/reader.php?date='.$_COOKIE["year"].$_COOKIE["month"].$_COOKIE["day"].'&type=feast&lang=AM');
$showliturt = file_get_contents('http://feed.evangelizo.org/reader.php?date='.$_COOKIE["year"].$_COOKIE["month"].$_COOKIE["day"].'&type=liturgic_t&lang=AM');
$showsaints = file_get_contents('http://feed.evangelizo.org/reader.php?date='.$_COOKIE["year"].$_COOKIE["month"].$_COOKIE["day"].'&type=saint&lang=AM');
if ( !empty($showfeast) ) {
echo ' - '.$showfeast;
}
else if ( !empty($showliturt) ) {
$stlit = strpos($showliturt, 'of the');
if ( $stlit ) {
$trunclitur = substr($showliturt, $stlit+7);
echo ' - '.$trunclitur;
}
else {
$stlits = strpos($showliturt, 'aint');
if ( $stlits ) {
;
}
else {
echo ' - '.$showliturt;
}
}
}
if ( !empty($showsaints) ) {
echo ' - '.$showsaints;
}
}
$widfeast = strlen($showfeast);
$widlitur = strlen($trunclitur);
$widsaint = strlen($showsaints);
$widtha = $widfeast + $widsaint;
$widthb = $widlitur + $widsaint;
if ($widtha > 240 || $widthb > 240) {
echo '<span>'.$showsaints.'</span>';
}
?>
</div> <!-- End Feast or Saint of the day -->
How do I tell the HTML page to reload this div after midnight of the current date? The problem is that the information shown is outdated the first few times I open the page the next day. Then it has the current information. I store the date in cookies, then with the date I get the other information. If I make the cookies expire too quickly, then I end up with no information at all. So I want to try to refresh the div automatically.
How do I make a jquery call to reload the div every few hours, with the PHP script shown?
Upvotes: 1
Views: 5325
Reputation: 29160
The PHP code is actually not relevant. The jQuery load()
function will load the resulting HTML from any PHP page into a specified div
This code will re-load the content into the div every 3,600,000 milliseconds (or every hour)
setInterval(function(){
$('#divId').load('theContent.php');
}, 3600000);
Upvotes: 1
Reputation: 114377
You need to set the number of milliseconds until midnight.
window.setTimeout(function() {
$('#myDiv').load('someScript.php');
},milliseconds)
Upvotes: 0