title: How do I receive data from a PHP echo to display using AJAX?
body: <p>Simply said: How do I receive data from a PHP echo to display using AJAX?</p>
  
  <p>I have the ability to use JQuery; however, I don't know if that would be right for the job or not.  I simply have a form in HTML which the user may input information, but as they are entering data, I want to check for availability against a database.  If the input checks and there's no problem, I don't want any text displayed, but if there's a problem then I want to display an error.  I currently have a sign-up form working with PHP and MySQL through a database, but I can't get the errors to echo out without having a page refresh.  Is there any way to show errors without refreshing?</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;form action="index.php" method="POST"&gt;
              &lt;table&gt;
                  &lt;tr&gt;
                      &lt;td colspan="3"&gt;&lt;h1&gt;New to the site?&lt;/h1&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;span class="login_text"&gt;Username:&lt;/span&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" class="inputs" name="signup_username" value="&lt;?php echo $username ?&gt;"&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;span class="login_text"&gt;Password:&lt;/span&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input type="password" class="inputs" name="signup_password"&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;span class="login_text"&gt;Password &lt;span style="color: #666666;"&gt;(repeat)&lt;/span&gt;:&lt;/span&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input type="password" class="inputs" name="signup_passwordrepeat"&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;span class="login_text"&gt;Email:&lt;/span&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" class="inputs" name="signup_email" value="&lt;?php echo $email ?&gt;"&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td colspan="2"&gt;&lt;input type="submit" id="signupbutton" class="subutton" style="font-family: Georgia, sans-serif;  font-size: 1.5em;  width: 265px;  height: 3em;" value="Sign Up!" name="signup_button"&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>&lt;?php
              $submit = $_POST["signup_button"];
              $username = mysql_real_escape_string($_POST["signup_username"]);
              $password = mysql_real_escape_string($_POST["signup_password"]);
              $repeatpassword = mysql_real_escape_string($_POST["signup_passwordrepeat"]);
              $email = mysql_real_escape_string($_POST["signup_email"]);
              $date = date(m.d.y);
  
              if($submit) {  //If the form is submitted
                  if($username &amp;&amp; $password &amp;&amp; $repeatpassword &amp;&amp; $email) {  //If everything is filled out
                      //Check length of username
                      if(strlen($username) &lt;= 16) {
                          $usercheck = mysql_query("SELECT * FROM artists WHERE username='$username'");
                          $usernum = mysql_num_rows($usercheck);
  
                          if($usernum == 0) {  //Check for availability of username
                              $emailcheck = mysql_query("SELECT * FROM artists WHERE email='$email'");
                              $emailnum = mysql_num_rows($emailcheck);
  
                              if($emailnum == 0) {  //Check for availability of email address
                                  if($password == $repeatpassword) {  //Check for identical password input
                                      //Encrypt password
                                      $password = sha1($password);
                                      $repeatpassword = sha1($repeatpassword);
  
                                      //REGISTER
                                      $register = mysql_query("INSERT INTO artists VALUES ('', '', '$username', '$password', '$email', '', '$date')");
                                      echo("Registration successful, please log in on the right!");
                                  }
                                  else
                                      echo("The passwords don't match!");
                              }
                              else
                                  echo("That email address has already been registered!");
                          }
                          else
                              echo("That username has already been registered!");
                      }
                      else
                          echo("The username you entered is too long!");
                  }
                  else
                      echo("Please fill out all fields!");
              }
          ?&gt;
  </code></pre>