0

I have a function that does something like this

for(i = 0; i< n; i++){
  for(j = 0; j<m; j++){
     $.post('/post', {
       ...
     }
   }
}

Is there any way to do something like an alert only after every post request is done?

Iván
  • 570
  • 5
  • 8
  • 3
    https://api.jquery.com/jquery.when/ – SLaks May 31 '18 at 20:10
  • If you have a variable number of requests, you can pair the `$.when` call with the apply method to give it a variable array, containing all the promises. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply – Taplar May 31 '18 at 20:13
  • Use the .done callback to check a variable: example https://plnkr.co/edit/AXlZ7eERmeYns1VE5m3u?p=preview – scotty3 May 31 '18 at 20:36
  • That works. Thanks @scotty3 – Iván May 31 '18 at 20:45

0 Answers0