Good day everyone. Please tell me how to solve this problem. There are 5 elements on page, which, when I click on a button, I have to update, using ajax requests, and immediately after updating all 5 fields, run the following function. I made a global variable count = 5 , and in the ajax request block for success , I decrement the global variable. But as I continue to hang a monitor or something in its likeness, which will be able to monitor this variable. Use callback, I understand it is useless here.

  • one
    if you can reduce the variable, then you can probably check it to 0 too? or you can make it an object with a setter that checks. - teran
  • I can check on 0, but functions with ajax requests work not only in this implementation. - Alexey
  • learn.javascript.ru/promise#parallelnoe-vypolnenie or simply Promise.all - Nikita R.
  • All this is good, but not just ajax requests come to me, let's say functions are started, in which there is a certain implementation after ajax is started. - Alexey

1 answer 1

Thank you all for your help. Solved the problem like this. I created a new function, where I’m not just decrementing the count variable, but checking after 0, if it’s 0, then I’ll start the next function.

  • and what will happen if you press the button again? - teran
  • will work again - Alexey