callback function does not change var when using getJSON function in jQuery
<p>I am trying to change a variable for validation purposes, the changes takes place inside a <code>$.getJSON()</code> function after the return of certain data.</p>

<p>The problem is after chaining the variable and outside the <code>$.getJSON()</code> the variable is returned to its original value. Here is the code for that part:</p>

<pre><code>var isValid = true; 
// Validate Username
var un = $('#username').val();
if(un.length &lt; 5) {
  isValid = false;
  $('#ins_username').html('').hide();
  $('#msg_username').html('Please fill username, minium 5 Characters').show();
  // to append to another msg
} else {
  $.getJSON("validateUsername.action", {
    'newStudent.users.username': $('#username').val()
    },function(json) {
      if ( json.jsonData.usernameFound == true ) {
        isValid = false;
        $('#ins_username').html('').hide();
        $('#msg_username').html('Please change username, Username Taken.').show();
        alert ("the isValid value inside the getJson() "+isValid);   
        // the isValid = false here as expected
        alert ("JOSN from inside "+json);  
      } else {
        $('#msg_username').html('').hide();
      }
  });
  alert ("the isValid value outside the getJson() "+isValid);   
  // the isValid = true here, i want the changes to remain
}
</code></pre>

<p>I am not sure what have I missed here.</p>
