weixin_33725270 2018-03-26 09:53 采纳率: 0%
浏览 7

发送前Ajax卡在

My Ajax Login form stuck at before send.

Which is the:

beforeSend: function()

I have tried to display the error but there is no error at all as it keeps stuck at the beforesending. Is it because of my PHP not returning back any data and affecting the JavaScript?

Ajax Script:

$('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 Script:

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


?>
  • 写回答

0条回答 默认 最新

    报告相同问题?