我设置了一个天气栏,使用 setInterval 和 .load 每 10 秒加载一个名为 data.php 的 php 文件。我可以在 Firebug 中看到 setInterval 正在工作,而且负载似乎也在工作,但是当它运行时,它没有获得最新版本的 data.php 文件。
索引.php
<div id="weather"></div>
<script>
var auto_refresh = setInterval(
function ()
{
$('#weather').load('assets/fb_weather/data.php');
}, 10000); // refresh every 10000 milliseconds
</script>
数据.php
<div id="fb_weather_wrapper">
<p id="fb_weather_today">Current</p>
<div id="fb_weather_top">
<div class="one-half">Mt. Carmel, IL</div>
<div class="one-half"><?=$today_date?></div>
<div class="clear"></div>
</div>
<div class="fb_weather_icons fb_weather_icons_<?=$cond->icon?>"></div>
<p id="fb_weather_temp"><? echo round($cond->temp_f); ?>°</p>
<p class="fb_weather_cond"><?=$cond->weather?></p>
<div id="fb_weather_forecast">
<ul>
<? foreach($forecast->forecast->simpleforecast->forecastdays->forecastday as $day)
{ ?>
<li class="fb_weather_day">
<div class="fb_weather_icons_small fb_weather_icons_small_<?=$day->icon?>"></div>
<p class="fb_weather_forecast_temp"><?=$day->high->fahrenheit?>°<br />
<p><?=$day->date->weekday_short?></p>
<em class="clear"></em>
</li>
<? } ?>
<em class="clear"></em>
</li>
</ul>
</div>
</div>