每分钟重新加载包含 PHP 脚本的 div
我的页面有一个 div,其中的内容是由 PHP 脚本编写的。
<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 -->
我如何告诉 HTML 页面在当前日期的午夜之后重新加载此 div?问题是我第二天打开页面的前几次显示的信息已经过时了。然后它就有当前的信息。我将日期存储在 cookie 中,然后通过日期获取其他信息。如果我让 cookie 过期得太快,那么我最终就不会得到任何信息。所以我想尝试自动刷新div。
如何进行 jquery 调用以每隔几个小时重新加载 div 并显示 PHP 脚本?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PHP 代码实际上不相关。 jQuery
load()
函数会将任何 PHP 页面生成的 HTML 加载到指定的 divhttp://api.jquery.com/load/
此代码将每 3,600,000 毫秒(或每小时)将内容重新加载到 div 中
The PHP code is actually not relevant. The jQuery
load()
function will load the resulting HTML from any PHP page into a specified divhttp://api.jquery.com/load/
This code will re-load the content into the div every 3,600,000 milliseconds (or every hour)
您需要设置距离午夜还有多少毫秒。
You need to set the number of milliseconds until midnight.