我的Ajax登录表在发送前停留。
这是:
beforeSend:function()
我试图显示错误,但没有任何错误,因为它一直停留在发送前。是因为我的PHP没有返回任何数据并影响JavaScript吗?
Ajax脚本:
$('document').ready(function()
{
/* validation */
$("#login-form").validate({
rules:
{
},
messages:
{
},
submitHandler: submitForm
});
/* validation */
/* form submit */
function submitForm()
{
var data = $("#login-form").serialize();
$.ajax({
type:'POST',
url : 'lgreg/post/login-post.php',
data : data,
beforeSend: function()
{
$("#error").fadeOut();
$("#login-submit").html('Logining ...');
},
success : function(data)
{
if(data===0){
$("#error").fadeIn(1000, function(){
$("#error").html('Please Activate Your Acount!');
$("#login-submit").html('Login');
});
}
else if(data=="success")
{
$("#login-submit").html('Redirecting...');
var delay = 1000;
setTimeout(function(){ window.location = "http://moonxyweb.com/emailconfirmation"; }, delay);
}
else{
$("#error").fadeIn(1000, function(){
//$("#error").html('Error occur, Please Contact Our Support!');
$("#error").html(data);
$("#login-submit").html('Login');
});
}
}
});
return false;
}
/* form submit */
});
PHP脚本:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once 'dbconfig.php';
if($_POST)
{
$user_name = $_POST['user_name'];
$user_password = $_POST['password'];
$lastlogin_date = date('Y-m-d H:i:s');
$password = password_hash( $user_password, PASSWORD_BCRYPT, array('cost' => 11));
$activation = "1";
try
{
$stmt = $db_con->prepare("SELECT * FROM tbl_user WHERE user_name=:name AND activation=:activation");
$stmt->execute(array(":name"=>$user_name , ":activation"=>$activation));
$count = $stmt->rowCount();
if($count==1){
$stmt = $db_con->prepare("SELECT * FROM tbl_user WHERE user_name=:name AND user_password=:password");
$stmt->execute(array(":name"=>$user_name , ":password"=>$user_password));
$check_acc = $stmt->rowCount();
if($check_acc == 1)
{
echo "success";
}
else
{
echo "wrong";
}
}
else{
echo "0";
}
}
catch(PDOException $e){
echo $e->getMessage();
}
}
?>