title: Setting the jQuery $.post return data to a JavaScript variable
body: <p>I have the following <code>jQuery</code> code in my HTML page:</p>
  
  <pre><code>$.post("MyPHP.php", {category: CATEGORY}, function(data){var test = data;});
  </code></pre>
  
  <p>But I can't seem to use test anywhere else in my page. I know this is <code>AJAX</code> so I have to wait for <code>$.post</code> to complete but the variable test is never set. If I instead use the return data to change the innerhtml of a paragraph, the paragraph updates after a small delay. </p>
  
  <p>Any thoughts?</p>
  
  <p>EDIT: Cracked it! You can call another function from the <code>$.post</code> return function, ie: <code>function(data){setVar(data)});</code> and simply define the <code>setVar(data)</code> function as follows:</p>
  
  <pre><code>function setVar(data){test = data;}
  </code></pre>
  
  <p>Provided test has already been defined in global scope <code>var test;</code> you can use it through out the rest of your code.</p>