我希望在循环中调用多个API(例如:$.each)。我可以使用async:false
模式来实现,但这会使脚本延迟。如何以同步模式实现此操作?仅忽略async
选项将使只有list
中的最后一个元素被发送到API调用。
$.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);
}
});
}
});
});