this question has answer here:
- how return response asynchronous call? 21 answers
i sending getjson request lastfm using code below. code within javascript script. can result getjson function , use outside of function variable, i.e. in within calling javascript?
function getartistinfo(lastfmartist) { var urlartist = 'http://ws.audioscrobbler.com/2.0/?callback=?', params = { method: "artist.getinfo", artist: lastfmartist, format: "json", api_key: "xxxxxxxxxx" }; $.getjson(urlartist, params, function(data) { var myartist = data.artist.bio.summary; }); } alert(myartist);
you use callback
function isfunction(object) { return (typeof object == 'function'); } function getartistinfo(lastfmartist, callback) { var urlartist = 'http://ws.audioscrobbler.com/2.0/?callback=?', var params = { method: "artist.getinfo", artist: lastfmartist, format: "json", api_key: "xxxxxxxxxx" }; $.getjson(urlartist, params, function(data) { var myartist = data.artist.bio.summary; if (isfunction(callback)) { callback(myartist); } }); } function getartistinfocomplete(myartist ) { alert(myartist); }
then call it
getartistinfo(lastfmartist, getartistinfocomplete);
Comments
Post a Comment