0
div#weather裏面有一些PHP調用Google的天氣XML。它很好,除了它變得陳舊。我想每隔600000毫秒重新加載一次div以獲得新的XML。重新加載div重新加載XML
我正在走一個JavaScript計時器的路徑,但似乎需要一個外部URL。
如果我需要在外部文件中有PHP,這沒什麼大不了的,只是不理想。
<div id="weather">
<?php
$URL = "http://www.google.com/ig/api?weather=60618";
$dataInISO = file_get_contents($URL);
$dataInUTF = mb_convert_encoding($dataInISO, "UTF-8", "ISO-8859-2");
$xml = simplexml_load_string($dataInUTF);
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
?>
<div class="weather-<?php $weather = $current[0]->condition['data']; $weatherclass = str_replace(' ','-',$weather); $weatherclass = strtolower($weatherclass); echo $weatherclass; ?>"> </div>
<div id="temp"><?= $current[0]->temp_f['data'] ?>°</div>
<div id="condition"><?= $current[0]->condition['data'] ?></div>
</div>
爲什麼不製作一個可以通過AJAX查詢的'weather.php'文件? – Blender 2012-08-08 02:01:23
除了Blender說的之外,我唯一能看到的就是在頁面上放置一個「元刷新」。去AJAX,這顯然是解決方案。 – Johnny5 2012-08-08 02:03:00
@Blender外部weather.php是好的,我只是希望在一個文件中保持簡單。感謝您的答覆。 – natejones 2012-08-08 02:10:13