0

setInterval と .load を使用して、data.php という名前の php ファイルを 10 秒ごとにロードするようにウェザー バーを設定しました。setInterval が機能していることを Firebug で確認できますが、ロードも同様に機能しているように見えますが、実行すると 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>
4

1 に答える 1

0

.load() メソッドを削除して、ajax リクエストを作成する必要があります。

お気に入り

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

データ文字列または配列は、ページに送信する値であり、この値を php ページに取得できます

お気に入り :

print_r($_POST);
于 2013-10-28T14:51:38.197 に答える