Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery YQL从rss变量中选择_Jquery_Variables_Rss_Quotes_Yql - Fatal编程技术网

jQuery YQL从rss变量中选择

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

所以我有一个变量woeid,我想输入w的值-

$.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+"&deg;");
                        $('#weatherText').html(w.condition.text+"");
                        $('#geolat').html(w.title+"");

                        $('#var').html(lat+"latitude");

                    });

            });
         </script> 

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

第二个YQL查询在发送第一个查询后立即发送。第二个查询只能在收到第一个查询的响应后进行,因为这是为第二个查询提供WOEID的原因

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


下面是一个快速重构的示例,

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

第二个YQL查询在发送第一个查询后立即发送。第二个查询只能在收到第一个查询的响应后进行,因为这是为第二个查询提供WOEID的原因

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


下面是一个快速重构的示例,

什么不起作用?你会犯什么错误?什么不起作用?你会犯什么错误?