loops - Run jquery function after $.each has finished using promise -
i have each loop pulls foursquare info. looks similar following:
$.getjson('https://api.foursquare.com/v2/venues/search?search_string_here', function(data) { $.each(data.response.venues, function(i,venues){ var content = foursquare stuff; $(content).appendto("#foursquare"); }); });
i need initiate function after each loop finished. works if placed after each loop:
$( "#foursquare" ).promise().done(function() { //do stuff });
i not familiar promise
- strange thing works selector. 2 questions:
1) best way of going each callback? 2) correct selector here? each isnt iterating on existing elements, unsure of 'promise'
$.getjson
return promise can use. called after callback.
var $ajax = $.getjson('url', function(data){ // $.each }); $ajax.done(function(){ // stuff });
Comments
Post a Comment