title: Why is my Javascript function no working as intended?
body: <p>This is my function:</p>
  
  <pre><code>function isLoggedIn(){
      $newuid = uid;
      alert("1");
  
      if(uid == null){return false;}
  
      $.getJSON("login.jsp",{uname: uname, upass : upass},function(data){
          alert("2");
          $newuid = data.uid;
      });
  
      alert("3");
      return $newuid == uid;
  }
  </code></pre>
  
  <p>It will alert 1 then 3 and then 2. Why is that and how can i fix it?</p>