jsonp技术访问天气Demo,该网站实现了返回数据为xml或json类型
注意:select*fromjsonwhereurl='..'要用空格隔开
*fromjsonwhereurl='http://m.weather.com.cn/data/101010100.html'
//返回一个xml的文档树(object类型)*fromjsonwhereurl='http://m.weather.com.cn/data/101010100.html'&format=json
//将返回的xml的文档树(object类型)转变为json类型(object) tianqi.jsp代码如下:<pageEncoding="utf-8"%>
<uri="/struts-tags"prefix="s"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN"""><htmlxmlns=""><headrunat="server"><title>注册</title><metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/><scripttype="text/javascript"src="../js/jquery-1.4.3.js"></script></head><body>
<fontcolor='red'>天气预报demo界面</font><divid="content">
文本框内容</div><script>$(function(){ $.getJSON("",{q:"select*fromjsonwhereurl='http://m.weather.com.cn/data/101010100.html'",format:"json"},
function(data){
var$content=$("#content")if(data.query.results){ varresult=JSON.stringify(data.query.results);$content.text(result);varobj=eval('('+result+')');alert(obj.weatherinfo.city);}else{ $content.text('nosuchcode:'+code);}});});</script></body><script></script></html>