Global variable not working
<p>I've been beating my head against the wall with this.  Can someone please tell me what I'm doing wrong?</p>

<pre><code>var foo = 100;

function loadData() {
   // this pops up a window that says it's 100
   alert(foo);  

   $.getJSON(myvars.constants.ajaxpath + "getsettings", function(data) {
      foo = 200;
      // this pops up a window that says it's 200
      alert(foo);
   });
   // this pops up a window that says it's 100
   alert(foo); 
}
</code></pre>

<p>Any value that I set the global variable to inside the getJSON() call is only valid within the getJSON() call.  Once the function exits the global variable reverts back to its previous value.</p>

<p>How can I set this global variable from within the getJSON() call?  I've tried using .success(), .complete(), etc. as well.  I want it to stay set to 200, not revert to 100.</p>

<p>Thanks!</p>

<p>P.S.  Obviously I'm doing other things with global variables in the getJSON() call, but the simple variable settings are to illustrate the issues.</p>
