title: jQuery AJAX Race Condition
body: <p>I've seen similar questions asked on SO but no quite my problem.</p>
  
  <p>I have something like</p>
  
  <pre><code>var x = 5;
  if( some condition ){
      $.ajax({
          url:"...",
          success: function(response){
              x = response.x;
          }
      }
  }
  some other logic
  use x variable
  </code></pre>
  
  <p>What is happening is the thread executing the JS gets to the logic that uses x before the asynchronous task comes back.</p>
  
  <p>Normally I would just put whatever logic inside the success function but I need the logic to happen regardless of whether or not the condition is met and I don't want to replicate code. Anyone have any suggestions? Should I just async to be false?</p>
  
  <p>Thanks!</p>