title: Check if username exists in database with AJAX
body: <p>I want to add a feature to my registration form which I will check if that username already exists in the database.</p>
  <p>I have a few questions about AJAX -</p>
  <ol>
  <li><p>I want to create an AJAX request on_change function, so something like this -</p>
  <pre><code>$('#username').change(function() {
    $.ajax({
    url: &quot;validation.php&quot;
    });
  });
  </code></pre>
  <p>So, as far as I understood, I must have all validations made in PHP inside the validation.php file, correct? Is there any special validation needed or can it be just simple validation with a sql statement - <code>SELECT * FROM 'users' WHERE 'username' = '. $_POST['username'];</code></p>
  </li>
  <li><p>So as I understood I must pass the POST values via $.ajax too, correct? If yes, how will I be able to access them via the validation.php file?</p>
  </li>
  <li><p>After I get the results in validation.php file, how can I pass them back (true or false -- exists or doesn't exist)? I will need to pass them back, and then do an if check, if it's true - show an error that the username already exists, otherwise, don't show anything?</p>
  </li>
  </ol>