Execute function after Ajax call is complete

后端 未结 6 2033
遇见更好的自我
遇见更好的自我 2020-11-30 03:16

I am new to Ajax and I am attempting to use Ajax while using a for loop. After the Ajax call I am running a function that uses the variables created in the Ajax call. The fu

6条回答
  •  清歌不尽
    2020-11-30 03:26

    Add .done() to your function

    var id;
    var vname;
    function ajaxCall(){
    for(var q = 1; q<=10; q++){
     $.ajax({                                            
             url: 'api.php',                        
             data: 'id1='+q+'',                                                         
             dataType: 'json',
             async:false,                    
             success: function(data)          
             {   
                id = data[0];              
                vname = data[1];
             }
          }).done(function(){
               printWithAjax(); 
          });
    
    
    
     }//end of the for statement
    }//end of ajax call function
    

提交回复
热议问题