title: jQuery function execution order
body: <p>I am having a problem, or perhaps a lack of understanding, with the jQuery execution order of <code>$.get()</code> function. I want to retrieve some information from a database server to use in the <code>$.ready()</code> function. As you all know, when the get returns, it passes the data to a return handler that does something with the data. In my case I want to assign some values to variables declared inside the ready handler function. But the problem is, the return handler of <code>$.get()</code> does not execute until after ready has exited. I was wondering if (a) am I doing this right/is there a better way or if (b) there was a way around this (that is, force the get return handler to execute immediately or some other fix I'm not aware of). I have a feeling this is some closure thing that I'm not getting about JavaScript.</p>
  
  <p>As per request, I'll post an example of what I mean:</p>
  
  <pre><code>$(function() {
      var userID;
  
      $.get(uri, function(returnData) {
                     var parsedData = JSON.parse(returnData);
                     userID = parsedData.userID;
                 });
    });
  </code></pre>
  
  <p>So as you can see, I'm declaring a variable in ready. Then using a get call to the database to retrieve the data needed. Then I parse the JSON that is returned and assign the userID to the variable declared before. I've tested it with a couple alerts. An alert after the get shows userID as undefined but then an alert in get's return handler shows it to be assigned.</p>