JQuery加载不替换内容

时间:2013-10-28 14:27:46

标签: 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 ()
    {
        $('#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); ?>&deg;</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?>&deg;<br />
                <p><?=$day->date->weekday_short?></p>
                <em class="clear"></em>
            </li>
            <? } ?>
                <em class="clear"></em>
            </li>

        </ul>
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

你必须删除.load()方法并发出ajax请求:

喜欢

$.post('assets/fb_weather/data.php','datastring/dataArray',function(response){
$('#weather').load('assets/fb_weather/data.php');
});  

数据字符串或数组是您要发送到页面的值,您可以将此值获取到您的php页面

喜欢:

print_r($_POST);