each wait until finish $.ajax , and then continue

∥☆過路亽.° 提交于 2019-11-30 13:47:58

Option 1: Switch to next element in your array in the success handler.

Option 2: Make ajax requests synchronously:

  • global:

     $.ajaxSetup({ async: false });
    
  • or directly in the request:

     $.ajax({
         async: false,
         type: "POST",
         url: domain+"/view_tasks/gen_tasks/",
         dataType: 'html',
         data: data,
         success: function(dt){
            $this.find('.contChildTasks').html(dt);
            childs=$this.children('.taskDesc').find('.has_child');
            if(childs.length!=0)
                genTask(childs);
            }
         }
    });
    

try put ajaxsetup({asynch:false}); before your each loop then after the loop reset it back to true so your future ajax request can still be asych

In your $.ajax call add async: false and it will send a blocking request.

Joel A. Villarreal Bertoldi

Set async to false on the $.ajax call.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!