jquery .ajax zawsze zwraca błąd - dane dodawane do bazy danych

Próbuję dodać użytkowników do bazy danych przy użyciu wywołań ajax jquery. Użytkownicy są dodawani do bazy danych dobrze, ale ajax zawsze zwraca błąd. Nie wiem też, jak pobrać konkretny błąd. Poniżej znajduje się mój kod, formularz, php i jquery.

Oto jquery

$(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');
            }
        });
    });
  });

Oto PHP

<?php
include 'class_lib.php';

if(isset($_POST['username'])) {
    $user = new Users;
    $user->cleanInput($_POST['username'], $_POST['password']);
    if($user->insertUser()) {
        echo json_encode('true');
    } else {
        echo json_encode('false');
    }
}

Oto HTML

<div id='newUser' class='tool'>
    <h3>New User</h3>
    <form method='post' name='newUser' data='../php/newUser.php'>
        <span>Username</span><input type='text' name='username'><br>
        <span>Password</span><input type='password' name='password'>
        <input type='submit' name='submit' class='button' style='visibility: hidden'>
    </form>
    <span class='result'> </span>
</div>

questionAnswers(5)

yourAnswerToTheQuestion