<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Start jQuery</title>
<script src="lib/jquery-1.2.6.min.js" type="text/javascript"></script>
<script type="text/javascript">
//http://www.jb51.net/article/16931.htm
//weather.xml
$(document).ready(function(){
$.ajax({
url:"http://www.google.com/ig/api?weather=suzhou",
dataType:"xml",
error: function(xml){
alert('Error loading XML document'+xml);
},
success:function(xml){
var str="";
$(xml).find("weather > forecast_information > postal_code").each(function(){
//alert("text:"+$(this).find("content").text());//each是循環執行,即多次彈出。
//取得屬性的方法
str= "城市代碼:"+$(this).attr("data") ;
});
str+="<br>日期:"+$("weather > forecast_information > forecast_date", xml).attr("data") ;
str+="<br>天氣:"+$("weather > current_conditions > condition", xml).attr("data") ;
$(xml).find("weather > forecast_conditions").each(function(){
//取得屬性的方法
str+="<br>日期:"+$(this).find("day_of_week").attr("data");
str+=" 溫度:"+$(this).find("low").attr("data")+"-"+$(this).find("high").attr("data");
str+=" 天氣:"+$(this).find("condition").attr("data");
});
$("#rating").html(str);
}
})
});
</script>
</head>
<body>
<div id="rating">請稍候,正在加載......</div>
</body></html>