jQuery YQL SELECT FROM rss变量

所以我有一个变量“woeid”,我正试图为“w”的价值投入 –

$.YQL("select * from rss where url='http://weather.yahooapis.com/forecastrss?w="+woeid"'",function(data){ 

为什么它不起作用?

编辑:整个脚本 –

  $(document).ready(function() { $.YQL = function(query, callback) { var encodedQuery = encodeURIComponent(query.toLowerCase()), url = 'http://query.yahooapis.com/v1/public/yql?q=' + encodedQuery + '&format=json&callback=?'; $.getJSON(url, callback); }; $.YQL("select place.woeid from flickr.places where lat=34.45 and lon=-118.54", function(data) { var w=data.query.results.places.place; woeid = w.woeid }); $.YQL("select * from rss where url='http://weather.yahooapis.com/forecastrss?w=" + woeid,function(data){ var w=data.query.results.item; var class=w.condition.text; var encodedclass = class.replace(/\s+/g, '-').toLowerCase(); $('body').addClass(encodedclass); $('#weatherTemp').html(w.condition.temp+"°"); $('#weatherText').html(w.condition.text+""); $('#geolat').html(w.title+""); $('#var').html(lat+"latitude"); }); });  

问题在于数据检索的异步性质。

第二个YQL查询在发送第一个YQL查询后立即发送出去。 第二个查询应仅在收到第一个查询的响应之后进行,因为这是为第二个查询提供WOEID的内容。

简而言之,将第二个$.YQL(…)调用移到第一个回调中。

这是一个快速重构的例子, http://jsbin.com/oruhe6