用php來寫一個天氣預報的模塊
天氣數據是通過采集中國氣象網站的
URL中的數字”
index
<?php
header("Content
?>
<html>
<meta http
<head>
<title>weather forecast</title>
<script type="text/javascript" src="ajax
<script type="text/javascript">
function $(id){
return document
}
function getCityId(){
var http_request=createAjax();
var url="weatherforecast
var data="cityid="+$("cityId")
("post"
("Content
(data);
function getWetherInfo(){
if{
var info=http_request
$("weatherinfo")
}
}
}
</script>
</head>
<body>
<select name="cityId" onchange="getCityId();" id="cityId">
<option>
<option value="
<option value="
<option value="
<option value="
<option value="
</select>
<span id="weatherinfo"></span>
</body>
</html>
weatherforecast
<?php
header("Content
header("Cache
if (isset($_POST[
$cityid=$_POST[
$url=$url="$cityid
}else {
$url="";
}
$weatherInfo_json=file_get_contents($url);
$weatherInfo=json_decode($weatherInfo_json
$cityName=$weatherInfo[
$cityTemp=$weatherInfo[
$cityWd=$weatherInfo[
$cityWs=$weatherInfo[
$cityTime=$weatherInfo[
$citySD=$weatherInfo[
echo $weatherinfo="城市名字
?>
From:http://tw.wingwit.com/Article/program/PHP/201311/20929.html