I am trying to write some nested ajax calls with the help of function and when. But currently, my then function is not working as expected. I want to call then function when all