0

Yahoo の YQL を使用して複数の関数を呼び出そうとしています。私が表示しようとしているのは、毎日の天気です。XML ファイルには、今日 [1] 明日 [2] 翌日などの [0] があります。コードを実行すると、最後に呼び出された番号が表示され、他の番号は読み込まれません。私はどこで間違っていますか?

<script type="text/javascript"       src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript">
// javascript will go here
$(function(weatherone){

var query = "select * from rss where url='http://xml.weather.yahoo.com/forecastrss/SPXX0050_f.xml'";
var cacheBuster = Math.floor((new Date().getTime()) / 1200 / 1000);
var url = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(query) + '&format=json&_nocache=' + cacheBuster;



window['wxCallback'] = function(data) {
    var info = data.query.results.item.forecast[0];
    $('#wxDay').text(info.day);
    $('#wxIcon').css({
        backgroundPosition: '-' + (61 * info.code) + 'px 0'
    }).attr({
        title: info.text
    });
    $('#wxIcon2').append('<img src="http://l.yimg.com/a/i/us/we/52/' + info.code + '.gif" width="74" height="74" title="' + info.text + '" />');
    $('#wxTemp').html(info.high + '&deg;' + (u.toUpperCase()));
    $('#wxText').html(info.text);
};

$.ajax({
    url: url,
    dataType: 'jsonp',
    cache: true,
    jsonpCallback: 'wxCallback'
});


});

$(function(weathertwo){

var query = "select * from rss where url='http://xml.weather.yahoo.com/forecastrss/SPXX0239_f.xml'";
var cacheBuster = Math.floor((new Date().getTime()) / 1200 / 1000);
var url = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(query) + '&format=json&_nocache=' + cacheBuster;



window['wxCallback'] = function(data) {
    var info = data.query.results.item.forecast[1];
    $('#wxDay').text(info.day);
    $('#wxIcon').css({
        backgroundPosition: '-' + (61 * info.code) + 'px 0'
    }).attr({
        title: info.text
    });
    $('#wxIcon2').append('<img src="http://l.yimg.com/a/i/us/we/52/' + info.code + '.gif" width="74" height="74" title="' + info.text + '" />');
    $('#wxTemp').html(info.high + '&deg;' + (u.toUpperCase()));
    $('#wxText').html(info.text);
};

$.ajax({
    url: url,
    dataType: 'jsonp',
    cache: true,
    jsonpCallback: 'wxCallback'
});


});
</script>
4

1 に答える 1

0

あなたがやる

window['wxCallback'] = function(data) { ... };
$.ajax({ ..., jsonpCallback: 'wxCallback' });

2回、2番目のクローバーが最初のクローバーです。別のコールバック名を使用するので、

window['wxCallback1'] = ...;
$.ajax({ ..., jsonpCallback: 'wxCallback1' });

window['wxCallback2'] = ...;
$.ajax({ ..., jsonpCallback: 'wxCallback2' });
于 2013-02-20T22:37:47.460 に答える