title: Jquery $.post() variable scope
body: <p>I'm not massively experienced with JavaScript and I'm having trouble with variable scope and jquery. I have the following structure:</p>
  
  <pre><code>function pass_variables()
  {
      username = "efcjoe"
      response = post_variables(username)
      alert(response)
  }
  
  function post_variables(username)
  {
      $.post(
          '/path/to/url/',
          {
              'username': username,
          },
          function(data)
          {
              valid = (data != 0) ? true : false
  
              // OPTION 1: If I put return here...
              return valid; // ... the alert box in pass_variables says "undefined"
          },
          "text"
      );
  
      // OPTION 2: If I put return here...
      return valid; // ... The alert box does not pop up, and Safari debug gives
                    //     me the error: "Can't find variable: valid"
  }
  </code></pre>
  
  <p>Am I missing something there? I think <code>valid</code> should be a global variable, and therefore option 2 should work fine. I'm really not sure about option 1.</p>
  
  <p>Can anyone give me any advice on the best way to get this working?</p>
  
  <p>Thanks a lot.</p>