如何定期更新雅虎天气/简单派的屏幕?
我正在使用雅虎天气提要和 simplepie 来获取我的数字显示器的天气。由于它是一个在屏幕上运行的网站,我无法一直手动刷新浏览器。
我只是想知道是否有什么东西,例如 jquery 或 php doc 可以帮助我随着天气变化定期更新天气信息?如果是这样,您能给我一些如何实施的指导吗?非常感谢您的帮助。
这是我的一些代码,以防万一有用
<div id="weather">
<div id="title">
<ul>
<!--<li> Outside Temp </li>-->
<li> Today </li>
<li> Tomorrow </li>
</ul>
</div> <!--title-->
<div id="forecast">
<div id="images">
<ul>
<?php foreach ($weather->get_forecasts() as $forecast): ?>
<li><img src="<?php echo $forecast->get_image(); ?>" alt="Weather" /></li>
<?php endforeach; ?>
</ul>
</div> <!--images-->
<div id="degrees">
<ul>
<?php foreach ($weather->get_forecasts() as $forecast): ?>
<li><?php echo $forecast->get_low(); ?>° <?php echo $forecast->get_high(); ?>° </li>
<?php endforeach; ?>
</ul>
</div><!--degrees-->
</div> <!--forecast-->
<!--</div> <!--second-->
一些标题部分信息:
<php
require_once('simplepie/simplepie.inc');
require_once('simplepie/simplepie_yahoo_weather.inc');
$feed = new SimplePie();
$feed->set_feed_url('http://weather.yahooapis.com/forecastrss?w=1234567&u=c');
$feed->set_item_class('SimplePie_Item_YWeather');
$feed->init();
$weather = $feed->get_item(0);
?>
非常感谢!
小号:)
I am using yahoo weather feed and simplepie to get weather for my digital display. Since it is a website run on a screen, I can't refresh the browser all the time manually.
I am just wondering is there anything eg jquery or php doc can help me update the weather information periodically as the weather changes?? If so would you be able to give me some directions on how to implement? your help is greatly appreciated.
Here is some of my code just in case it is useful
<div id="weather">
<div id="title">
<ul>
<!--<li> Outside Temp </li>-->
<li> Today </li>
<li> Tomorrow </li>
</ul>
</div> <!--title-->
<div id="forecast">
<div id="images">
<ul>
<?php foreach ($weather->get_forecasts() as $forecast): ?>
<li><img src="<?php echo $forecast->get_image(); ?>" alt="Weather" /></li>
<?php endforeach; ?>
</ul>
</div> <!--images-->
<div id="degrees">
<ul>
<?php foreach ($weather->get_forecasts() as $forecast): ?>
<li><?php echo $forecast->get_low(); ?>° <?php echo $forecast->get_high(); ?>° </li>
<?php endforeach; ?>
</ul>
</div><!--degrees-->
</div> <!--forecast-->
<!--</div> <!--second-->
Some header part info:
<php
require_once('simplepie/simplepie.inc');
require_once('simplepie/simplepie_yahoo_weather.inc');
$feed = new SimplePie();
$feed->set_feed_url('http://weather.yahooapis.com/forecastrss?w=1234567&u=c');
$feed->set_item_class('SimplePie_Item_YWeather');
$feed->init();
$weather = $feed->get_item(0);
?>
Thank you very much!
S:)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您尚未使用 JavaScript,因此定期刷新页面的一个非常简单的方法可能是使用 元刷新标签。尽管已弃用,但它可能是获取动态页面的快速方法。只需将标记添加到页面的
即可:
但是,您可能需要考虑使用 ajax 将内容加载到页面中。这可能不是最好的方法,但这里有一些快速而肮脏的代码。
在主页中,您可以使用 jQuery
load
定期访问 URL用于您的 PHP 脚本并将内容加载到div
中进行显示:其中
weather.php
可能如下所示:Since you're not already using JavaScript, a really simple way for you to periodically refresh the page might be to use the meta refresh tag. Although deprecated, it might be a quick way for you to get dynamic pages. Simply add the tag to the
<head>
of the page:However, you might want to consider using ajax to load your content into the page instead. This might not be the best possible approach to this but here's some quick and dirty code.
In the main page, you could use jQuery
load
to periodically hit the URL for your PHP script and load the content into adiv
for display:where
weather.php
might look something like this: