加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

jsonp技术访问天气Demo

发布时间:2020-12-16 19:20:41 所属栏目:百科 来源:网络整理
导读:jsonp技术访问天气Demo,该网站实现了返回数据为xml或json类型 注意:select *fromjsonwhereurl='..'要用空格隔开 http://query.yahooapis.com/v1/public/yql?q=select*fromjsonwhereurl='http://m.weather.com.cn/data/101010100.html' //返回一个xml的文档

jsonp技术访问天气Demo,该网站实现了返回数据为xml或json类型

注意:select*fromjsonwhereurl='..'要用空格隔开

http://query.yahooapis.com/v1/public/yql?q=select*fromjsonwhereurl='http://m.weather.com.cn/data/101010100.html'
//返回一个xml的文档树(object类型)

http://query.yahooapis.com/v1/public/yql?q=select*fromjsonwhereurl='http://m.weather.com.cn/data/101010100.html'&format=json
//将返回的xml的文档树(object类型)转变为json类型(object)


tianqi.jsp代码如下:

<%@pagepageEncoding="utf-8"%>
<%@tagliburi="/struts-tags"prefix="s"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<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("http://query.yahooapis.com/v1/public/yql",

{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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读