2013-02-20 5 views
0

나는 야후의 YQL을 사용하여 여러 함수를 호출하려고한다. 내가 표시하려고하는 것은 매일의 날씨입니다. XML 파일에는 내일 [2] 내일 이후 [1]에 대한 [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> 
+0

WTH 커스텀'jsonpCallback'을 사용합니까? – Bergi

답변

0

당신은 두 번

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

을하고 두 번째는 첫 번째 내리 쳤을 때. 다른 콜백 이름을 사용하십시오. 따라서

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

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

나에게이 사실을 설명해 주셔서 감사합니다. 완벽하게 작동합니다! – ServerSideSkittles

관련 문제