javascript中WOEID(使用YQL或rss)的天气预报
Weather forecast from WOEID (using YQL or rss) in javascript?
有什么方法可以从javascript中的woeid获取天气预报吗?
我试着使用雅虎的rss提要,但无法使用。这是我的代码
var url = "http://weather.yahooapis.com/forecastrss?w=" + encodeURIComponent('WOEID here');
$.ajax({
url: url,
dataType: 'jsonp',
jsonpCallback: function(data) { console.log(data); },
success: function(data) { alert("success"); }
});
有什么建议吗?
以下是使用jQuery和YQL:获得所需信息的最简单方法
var woeid = "26355493";
var $url = "http://query.yahooapis.com/v1/public/yql?callback=?";
$.getJSON($url, {
q: "select * from xml where url=" +
"'"http://weather.yahooapis.com/forecastrss?w=" + woeid + "'"",
format: "json"
}, function (data) {
console.log(data.query.results.rss.channel);
}
);
YQL控制台中的查询。。。
jsfiddle中的JavaScript代码。。。
显然,Weather API以RSS
格式返回其结果,而您的函数期望它们以jsonp
格式返回。考虑使用雅虎!管道为您获取天气RSS
提要,对其进行处理,并以jsonp
格式返回。
这是一个做类似事情的管道:
http://pipes.yahoo.com/pipes/pipe.info?_id=4d160cd8ed9d6d78164213928a51507d
正如dragon所建议的,我创建了一个Yahoo Pipe——这是我的完整代码;代码中的url是我创建的Yahoo Pipe。
$(function(){
var url = "http://pipes.yahoo.com/pipes/pipe.run?_id=e33143abd20b19a0173b3a4b479fa4d3&_render=json&w=YOURWOEIDHERE";
function createRequest() {
try { return new XMLHttpRequest(); } catch(e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
return null;
}
var request = createRequest();
request.open("GET", url, true);
request.onreadystatechange = callback;
request.send(null);
function callback() {
if(request.readyState != 4) { return }
Obj = $.parseJSON(request.responseText);
console.log(Obj);
}
});
引用:
雅虎管道:http://pipes.yahoo.com/pipes/pipe.info?_id=e33143abd20b19a0173b3a4b479fa4d3
jQuery 1.5-JSON错误标签无效
相关文章:
- 无法从 jQuery RSS Feed 中的 localStorage 动态替换类
- simpleweather js天气图标
- Cordova RSS馈送的链接不会在外部浏览器中打开
- 使用jQuery for RSS看不到多个帖子
- 如何使用jquery解析具有相同标签名称的yahoo天气api数据
- 如何编辑从RSS获得的URL
- document.evalute无法处理RSS源页面
- 无法使用开放天气图 API 异步获取天气
- 如何在网站上显示天气雷达地图
- 使用Google Feeds API获取RSS Feed标题
- 如何加载特定天气条件下的图标?(AngularJS)
- 使用Angularjs从rss渲染博客
- 外部解析RSS提要,不需要像谷歌和服务器端那样的任何库
- 为每小时天气预报制作滑块
- javascript中WOEID(使用YQL或rss)的天气预报
- 天气预报,使用angularjs和openweathermap将数据从旧数组推送到新数组中
- 创建天气预报最简单的方法是什么?
- 地下十天天气预报
- 雅虎天气预报xml
- 天气RSS提要