Javascript JQuery加载不替换内容
我设置了一个天气栏,使用setInterval和.load每隔10秒加载一个名为data.php的php文件。我可以在Firebug中看到setInterval正在工作,看起来负载太大了,但是当它运行时,它没有得到data.php文件的最新版本 index.phpJavascript JQuery加载不替换内容,javascript,php,jquery,Javascript,Php,Jquery,我设置了一个天气栏,使用setInterval和.load每隔10秒加载一个名为data.php的php文件。我可以在Firebug中看到setInterval正在工作,看起来负载太大了,但是当它运行时,它没有得到data.php文件的最新版本 index.php <div id="weather"></div> <script> var auto_refresh = setInterval( function () {
<div id="weather"></div>
<script>
var auto_refresh = setInterval(
function ()
{
$('#weather').load('assets/fb_weather/data.php');
}, 10000); // refresh every 10000 milliseconds
</script>
var auto_refresh=setInterval(
函数()
{
$('weather').load('assets/fb#u weather/data.php');
}, 10000); // 每10000毫秒刷新一次
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>
当前天气
伊利诺伊州卡梅尔山
您必须删除.load()方法并发出ajax请求:
像
数据字符串或数组是要发送到页面的值,您可以将这些值发送到php页面
比如:
print_r($_POST);
听起来你可能是可怕的缓存的受害者。你有没有试过在你的URL上加上时间戳<代码>$(“#weather”).load('assets/fb#u weather/data.php?timestamp=”)
另外,请注意,如果服务器出现问题,无论前一个请求是否成功,这都将保持每10秒运行一次,快速解决方案是使用setTimeout
并在回调中重新启动函数,nice和recursive。
print_r($_POST);