javascript - function call with Json-Object, wich contains a function. how to get return variable outside the function? -


i use jfeed plugin read information rss-feed in javascript. can use plugin this:

jquery.getfeed({     url: 'rss.xml',     success: function(feed) {         alert(feed.title);     } }); 

no want make function, returns feed information this:

function getfeed(feedurl) {     message ="error";      jquery.getfeed({         url: 'http://www.spiegel.de/schlagzeilen/tops/index.rss',         success: function(feed) {             message = feed;         }     });      return message; } 

it not work. how can feed varibale outside scope of jquery.getfeed(...) ?

it wont work way, since method jquery.getfeed asynchronous , return called earlier.

you need use callback feeds, this:

function getfeed(feedurl, callback){      message ="error";      jquery.getfeed({       url: 'http://www.spiegel.de/schlagzeilen/tops/index.rss',       success: function(feed) {          callback(feed);       }     }); }  getfeed(feedurl, function(feeds_returned) {   console.log(feeds_returned); }); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -