Waiting on multiple asynchronous calls to complete before continuing

后端 未结 4 1322
再見小時候
再見小時候 2020-11-29 02:04

So, I have a page that loads and through jquery.get makes several requests to populate drop downs with their values.

$(function() {
    LoadCategories($(\'#C         


        
4条回答
  •  被撕碎了的回忆
    2020-11-29 02:51

    But, I don't want to have to put a bunch of flags in the end of the drop down population callbacks, that I then check, and have to have a recursive setTimeout call checking, prior to calling LoadContact();
    No need for setTimeout. You just check in each callback that all three lists are populated (or better setup a counter, increase it in each callback and wait till it's equal to 3) and then call LoadContact from callback. Seems pretty easy to me.

    ajaxStop approach might work to, I'm just not very familiar with it.

提交回复
热议问题