Q:

Ajax to PHP form submission. Keep getting "parsererror"

ajaxSubmit.js:
$(document).ready(function(){
$('#submit').click(function() {

    $('#waiting').show(500);
    $('#reg').hide(0);
    $('#message').hide(0);

    $.ajax({
        type : 'POST',
        url : 'post.php',
        dataType : 'json',
        data: {
            login : $('input#login').val(),
            pass : $('input#pass').val(),
            pass1 : $('input#pass1').val()
        },
        success : function(data){
            $('#waiting').hide(500);
            $('#message').removeClass().addClass((data.error === true) ? 'error' : 'success')
                .text(data.msg).show(500);
            if (data.error === true)
                $('#reg').show(500);
        },
        error : function(XMLHttpRequest, textStatus, errorThrown) {
            $('#waiting').hide(500);
            $('#message').removeClass().addClass('error')
                .text(textStatus).show(500);
            $('#reg').show(500);
        }
    });

    return false;
});

});
HTML Form: 
   <div id="message" style="display: none;">

        </div>
        <div id="waiting" style="display: none;">
            Please wait<br />
            <img src="images/ajax-loader.gif" title="Loader" alt="Loader" />
        <br />
        </div>
  <form id="reg" class="form with-margin" name="reg"  method="post" action="">
            <br />
            <p class="inline-small-label">
                <label for="login"><span class="big">Email</span></label>
                <input type="text"  name="login" id="login" value="">
            </p>
            <p class="inline-small-label">
                <label for="pass"><span class="big">Password</span></label>
                <input type="password" name="pass" id="pass"  value="">
            </p>
            <p class="inline-small-label">
                <label for="pass1"><span class="big">Password Again</span></label>
                <input type="password" name="pass" id="pass1"  value="">
            </p>

            <div align="center"><button type="submit"  name="submit" id="submit" >Register</button></div>

        </form>

    <script type="text/javascript" src="js/ajaxSubmit.js"></script>

post.php: 
    <?php

sleep(3);
$login = $_POST['login'];
$pass = $_POST['pass'];
$pass1 = $_POST['pass1'];
$login = mysql_real_escape_string($login);
$pass = mysql_real_escape_string($pass);
$pass1 = mysql_real_escape_string($pass1);

if (empty($login)) {
    $return['error'] = true;
    $return['msg'] = 'You did not enter you email.';
}
else if (empty($pass)) {
    $return['error'] = true;
    $return['msg'] = 'You did not enter you password.';
}
else if ($test == false) {
    $return['error'] = true;
    $return['msg'] = 'Please enter a correct email. This will be verified';
} 
else if (empty($pass)) {
    $return['error'] = true;
    $return['msg'] = 'You did not enter you password twice.';
}
else if ($pass != $pass1) {
    $return['error'] = true;
    $return['msg'] = 'Your passwords dont match.';
}

else {
    $return['error'] = false;
    $return['msg'] = 'Thanks! Please check your email for the verification code!';
}

echo json_encode($return);

?>

Any ideas why I keep getting the parsererror? 

A:

you have a $test variable else if ($test == false) that is undefined.
I'd suggest that if you are having parse errors through ajax, that you just load up the .php file manually and then php will point you to the line that the error is occurring on.

