title: How to wait for ajax success handler to finish before executing another
body: <p>I have the following scenario in my javascript:</p>
  
  <ol>
  <li>Ajax loads a record.</li>
  <li>Based on the return value of that record, another ajax call grabs a html form that is added into the DOM</li>
  <li>When #2 is complete, the records that were obtained from #1 are then loaded into the form created in #2.</li>
  </ol>
  
  <p>I am using the <code>when</code> so that when #2 is complete, I can load the form values from #1. The problem is, is that it appears that when doesn't wait for the success handler to finish, only the ajax call itself. I need to wait for the success function of #2 to complete (as this is what created the form in the DOM) before I can continue with loading the form with values.</p>
  
  <p>If I add an <code>alert1</code> at step #2, it works (which I'm guessing is because it is waiting for the alert to be clicked, and in that time, the success handler has finished.</p>