title: How to wait until the async request is complete
body: <p>I've an ajax registration form. The user may type in the desired username in the input field and then immediately hit the register button, while the ajax request to check if the username is available or not wasn't completed. For this case I want the actions of the register button to start executing only if the ajax request to check username is complete, otherwise wait for it to complete and then proceed. How to do this?</p>
  
  <p>I want the username validation function to remain asynchronous because it executes every time the user does a key-up on the input field.</p>
  
  <p>One way is to enter into a setTimeout() loop when the register button is clicked, and to stay in it until the flag is good. Another way is to call a synch username check request if the asynch request isn't complete. Is there a better method?</p>
  
  <p>It'll be nice if you give answer without using jQuery.</p>