I want to call several APIs inside a loop (for example: $ .each). I can do this using async:false mode, but it does lag the script. How to achieve this in synchronous mode? Just ignoring the async option allows you to send only the last item in list to api calls.
$.each(lists, function(index, value) { channel = lists[index].channel; list = lists[index].list; $.ajax({ url : 'api.php?list=' + list + '&from=' + from + '&to=' + to, dataType : 'json', async : false, success : function(data) { obj = data; $.ajax({ url : 'api.php?list=' + list + '&from=' + from + '&to=' + to + '&action=sender', dataType : 'json', async : false, success : function(data) { obj['senders'] = data.msg; CommonContainer.inlineClient.publish(channel, obj); } }); } }); });
source share