-1

I am making nested Ajax call, here is code for that:

function getCheckListId() {
var authToken = getCookie("aqs_authToken");
//Lets say AjaxCall1
$.ajax({
....
// Basic Ajax definition (type, url, etc.....)
....

 success: function (result) {
 for (var i=0; i< result.length;i++) // ForLoop AjaxCall1
 {
 var sample= result[i].checklistDetailId;

// Lets say AjaxCall2
 $.ajax({  
   url: 'URL' +sample
    // Code for Another Ajax Call
    success: function(result) {

    for(var i=0; i<result1.length; i++) {    { ... Some code.. } 
       } // END ForLoop AjaxCall2

     toSendEmail();
     // This is function call in which I am posting data (AjaxCall3)
      }, // Success Function close for AjaxCall2

    error: function(error) {.. some code.. }
     } // Error function close for AjaxCall2
    }
    }); // Close of AjaxCall2

   },  // Success Function close for AjaxCall1
   error: function (error) {
     alert("Some Statement");
      }  // Error Function Close for AjaxCall1


  });

}

I am making AjaxCall2 in AjaxCall1' Success function. But my AjaxCall2 is not getting executed it is directly making the call to function toSendEmail() I had look around and I tried like making function inside function (nested function) to make my ajax call executed but still not working. Can anyone suggest me any another way to execute it? or What I need to change to get my AjaxCall2 executed BEFORE controller calls toSendEmail() method?

Thank You

1 Answers1

1

toSendEmail() needs to go inside:

success: function(result) { ... Some code.. },.

Otherwise it will run before your second ajax call has returned. You are correctly calling the second ajax call in the success handler of the first, now you just need to put your final step inside the success handler of the second ajax call.

Mark
  • 90,562
  • 7
  • 108
  • 148