title: Getting variable value from PHP with jQuery
body: <p>So how do i get variable value from php file with jquery...?
  the jquery code is in other file (tpl)</p>
  
  <p>for example i have register.php and register.tpl (template file for register.php)</p>
  
  <p><strong>register.php</strong></p>
  
  <pre><code> ...some includes here...
  
  
  
  if(isset($_POST['submit'])) {
      $username = mysql_real_escape_string(trim($_POST['username']));
      $email = mysql_real_escape_string(trim($_POST['email']));
      $check = $mysql-&gt;query("SELECT username FROM ".TBL_USERS." WHERE username = '".$username."' OR email = '".$email."'");
  $rows_check = mysql_num_rows($check);
  if($rows_check &gt; 0) {
      echo 1;
  } else {
      $password = mysql_real_escape_string($_POST['password']);
          $salt = generate_salt($email);
          $hash = hash_password($password, $salt);
          $q = $mysql-&gt;query("INSERT INTO ".TBL_USERS." (username, password, email, salt) VALUES ('".$username."', '".$hash."', '".$email."', '".$salt."')");
          if($q) {
              header("Location: index.php");
          } else {
              die(mysql_error());
          }   
      }
  } else {
  .. calling parse template function ...
  }
  </code></pre>
  
  <p><strong>register.tpl</strong></p>
  
  <pre><code> ..jquery library included..
      &lt;form id="register" action="register.php" method="post"&gt;
         &lt;tr&gt;
         &lt;td&gt;Username&lt;/td&gt;
         &lt;td&gt;&lt;input type="text" id="username" name="username" class="register" style="width: 200px;" /&gt;
      &lt;/td&gt;
  </code></pre>
  
  <p>
   
     email
     
  
     
          ...other inputs...
          
              
                $("#username").blur(function()
      {</p>
  
  <pre><code>var email_v = $("#email").val();
   $("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
   $.post("register.php",{ username:$(this).val(), email: email_v, submit: true } ,function(data)
   {
    if(data=="1") 
    {
     $("#msgbox").fadeTo(200,0.1,function()
     {
  
      $(this).html('This User name Already exists').addClass('messageboxerror').fadeTo(900,1);
     });
    }
    else
    {
     $("#msgbox").fadeTo(200,0.1,function() 
     {
      $(this).html('Username available to register').addClass('messageboxok').fadeTo(900,1);
     });
    }
   });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>when i changed the whole register.php for testing purposes to
  
  or
  
  the script worked...however with the original version it shows always that username is available...</p>