php - Ajax stuck at before send

845

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


?>

People are also looking for solutions to the problem: mysql - Asking With Login PHP Mysqli

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.