Friday, 15 January 2010

jquery - Calling multiple functions in Javascript -



jquery - Calling multiple functions in Javascript -

i trying phone call multiple functions using yahoo's yql. trying display weather each day. xml file has [0] todays [1] tomorrow [2] day after etc. when run code looks @ lastly number called , not load others. going wrong?

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> <script type="text/javascript"> // javascript go here $(function(weatherone){ var query = "select * rss 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 * rss 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>

you do

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

twice , sec clobbers first. utilize different callback name, so

window['wxcallback1'] = ...; $.ajax({ ..., jsonpcallback: 'wxcallback1' }); window['wxcallback2'] = ...; $.ajax({ ..., jsonpcallback: 'wxcallback2' });

javascript jquery ajax json

No comments:

Post a Comment