each wait until finish $.ajax , and then continue

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);
            }
         }
    });
    

Tags:

Ajax

Jquery

Each