title: jquery .ajax always returns error - data being added to database
body: <p>I am trying to add users to a database using jquery ajax calls. The users get added just fine to the database, but the ajax always returns with error. I'm not sure how to retrieve the specific error either. Below is my code, form, php, and jquery. </p>
  
  <p>Here is the jquery</p>
  
  <pre><code>$(document).ready(function() {
  
      //ajax call for all forms. 
      $('.button').click(function() {
          var form = $(this).closest('form');
          $.ajax({
              type: "POST",
              url: form.attr('data'),
              dataType: 'json',
              data: form.serialize(),
              success: function (response) {
                  alert('something');
              },
              error: function() {
                  alert('fail');
              }
          });
      });
    });
  </code></pre>
  
  <p>Here is the PHP</p>
  
  <pre><code>&lt;?php
  include 'class_lib.php';
  
  if(isset($_POST['username'])) {
      $user = new Users;
      $user-&gt;cleanInput($_POST['username'], $_POST['password']);
      if($user-&gt;insertUser()) {
          echo json_encode('true');
      } else {
          echo json_encode('false');
      }
  }
  </code></pre>
  
  <p>Here is the HTML</p>
  
  <pre><code>&lt;div id='newUser' class='tool'&gt;
      &lt;h3&gt;New User&lt;/h3&gt;
      &lt;form method='post' name='newUser' data='../php/newUser.php'&gt;
          &lt;span&gt;Username&lt;/span&gt;&lt;input type='text' name='username'&gt;&lt;br&gt;
          &lt;span&gt;Password&lt;/span&gt;&lt;input type='password' name='password'&gt;
          &lt;input type='submit' name='submit' class='button' style='visibility: hidden'&gt;
      &lt;/form&gt;
      &lt;span class='result'&gt; &lt;/span&gt;
  &lt;/div&gt;
  </code></pre>