jQuery YQL从rss变量中选择
所以我有一个变量woeid,我想输入w的值-jQuery YQL从rss变量中选择,jquery,variables,rss,quotes,yql,Jquery,Variables,Rss,Quotes,Yql,所以我有一个变量woeid,我想输入w的值- $.YQL("select * from rss where url='http://weather.yahooapis.com/forecastrss?w="+woeid"'",function(data){ 为什么不起作用 编辑:整个脚本- <script> $(document).ready(function() { $.YQL = function(query, callba
$.YQL("select * from rss where url='http://weather.yahooapis.com/forecastrss?w="+woeid"'",function(data){
为什么不起作用
编辑:整个脚本-
<script>
$(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");
});
});
</script>
问题在于数据检索的异步性 第二个YQL查询在发送第一个查询后立即发送。第二个查询只能在收到第一个查询的响应后进行,因为这是为第二个查询提供WOEID的原因 简而言之,将第二个$.YQL…调用移动到第一个的回调中
下面是一个快速重构的示例,问题在于数据检索的异步性 第二个YQL查询在发送第一个查询后立即发送。第二个查询只能在收到第一个查询的响应后进行,因为这是为第二个查询提供WOEID的原因 简而言之,将第二个$.YQL…调用移动到第一个的回调中
下面是一个快速重构的示例,什么不起作用?你会犯什么错误?什么不起作用?你会犯什么错误?