0

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 表单:

   <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);


?>

任何想法为什么我不断收到解析器错误?

4

1 回答 1

1

你有一个else if ($test == false)未定义的 $test 变量。

我建议如果您通过 ajax 解析错误,您只需手动加载 .php 文件,然后 php 会将您指向发生错误的行。

于 2010-12-25T21:15:07.903 回答