0
我有一個天氣欄設置爲每10秒使用setInterval和.load加載一個名爲data.php的php文件。我可以在Firebug中看到setInterval正在工作,它看起來像負載太多,但是當它運行時,它不會獲得data.php文件的最新版本。JQuery加載不替換內容
的index.php
<div id="weather"></div>
<script>
var auto_refresh = setInterval(
function()
{
$('#weather').load('assets/fb_weather/data.php');
}, 10000); // refresh every 10000 milliseconds
</script>
data.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>
聽起來你可能是可怕的高速緩存的受害者。你有沒有嘗試添加一個時間戳到你打電話的URL? ''('#weather')。load('assets/fb_weather/data.php?timestamp =');' –
Jonathon
另外,要小心,如果服務器上的某些東西壞了,這隻會持續運行,每10秒,無論前一個請求是否成功,一個快速解決方案是使用'setTimeout'並重新啓動回調函數,nice和遞歸。 – tymeJV