title: Waiting for $.post to finish
body: <p>It appears that my script does not want to wait for the $.post call to finish. Thats a problem. Here is some pseudo code:</p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript"&gt;
  $(document).ready(function(){
    // Global var, to be used everywhere in the ready scope 
    // Note its default value!    
    var test = false;
    $.post('test.php',{},function(result){
     if(result=='yes')
     {
      // This gets executed!
      alert('Its true! Hurraaay!');
      test = true;
     }
     else
     {
      test = false;
     }
    }
  
    if(test==false)
    {
     // THIS gets executed, despite the fact that we set test to true!
     alert('Awww....');
    }
    // it reaches this, showing us that there was no error!
    alert('Im alive!!!');
    // and a whoooole bunch of other code here...
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>What is the best way to make sure that my Post call is finished before continuing, without hanging the browser? Hoping for something that is not too messy. :)</p>