maintain value of variable outside function in javascript? -
i try manipulate variable inside function. seems forget values once exit function, eventhough variable declared outside function.
the essential code:
var posts = {}; // perform data request // skjutsgruppens-page $.oajax({ url: "https://graph.facebook.com/197214710347172/feed?limit=500", *snip* success: function(data) { $.extend(posts, data); } }); // gruppen $.oajax({ url: "https://graph.facebook.com/2388163605/feed?limit=500", *snip* success: function(data) { $.extend(posts, data); } }); the oajax retrievies data facebook. want make variable contains data both oajax methods.
the actual code: http://eco.nolgren.se/demo/resihop/#
the issue success function executes @ arbitrary time in future--unless access posts after know success function has executed, receive undefined results, dependent on function , access timing.
the best approach handle correctly doing necessary work inside in success function, or use jquery's .when function.
Comments
Post a Comment