title: getJSON success function out of scope
body: <p>I just have started writing AJAX functions using jquery. Here i am calling <code>myfunction()</code>. where check.php is returning <code>{"count":1}</code> or <code>{"count":0}</code> for which myfunction is always returning <code>retval=false</code> . But for <code>{"count":1}</code> it should return true. I dont know where i am wrong. Below is the code i am using.</p>
  
  <pre><code>function myfunction(){
  var retval=false;
  if($('#tag').val() != ''){
      var query=$( "#tag" ).val();
      $.getJSON("check.php",{
          q: query
      },function(data){
          if(data.count==0){
              $('#formerrormsg').html('Error msg');
          }
          else{
              retval=true;
          }
      });
  }
  return retval;
  }
  </code></pre>
  
  <p>Please Help me to understand this. </p>