首頁  >  文章  >  web前端  >  用javascript為頁面加入天氣顯示實現思路及程式碼_javascript技巧

用javascript為頁面加入天氣顯示實現思路及程式碼_javascript技巧

WBOY
WBOY原創
2016-05-16 17:11:131361瀏覽
複製程式碼程式碼如下:





函數載入(cid)
{
var xmlhttp;
if (window.XMLHttpRequest)
{// IE7、Firefox、Chrome、Opera、Safari 的程式碼
xmlhttp=new XMLHttpRequest();
}
else
{// IE6、IE5 代碼
xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","date.jsp?cid=" cid,false);
xmlhttp.send();
var obj = eval("(" xmlhttp.responseText ")");
//var obj=JSON.parse(xmlhttp.responseText); //IE8以上
document.getElementById("test").innerHTML=objj .weatherinfo.city ":" obj.weatherinfo.weather1 " " obj.weatherinfo.temp1;
}
腳本>
頭>

天氣狀況


;


身體>


date.jsp
複製代碼程式碼如下:


String cid = request.getParameter("cid");
URL url = new URL("http://m.weather.com.cn/data/" cid ".html");
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.connect();
InputStream cin = httpConn.getInputStream();
BufferedReader reader = new BufferedReader(new InStreamedReader(new InStreamedReader reader = new BufferedReader(new InStreamedReader(new InStreamedReader reader = new BufferedReader(new InStreamedReader(new InStreamedReader reader = new BufferedReader(new InStreamedReader(new InStreamedReader reader = new BufferedReader(new InStreamedReader(new InStream) -8"));
StringBuffer sb = new StringBuffer();
字串rl = null;
while ((rl = reader.readLine()) != null)
sb.append (rl);
out.println(sb);
%>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn