How to check the login using jquery post?

I am trying to create a login test application using jquery post, php ..
It is reading the value but not sending the data to server.php and returning the data.

HTML CODE

<div class="contact-form pad-25">
    <div class="subpage-title">
    <h5>Please Login</h5>
</div>
<div>
    <div class="row">
       <div class="col-md-4">
          <input class="form-control" placeholder="Name" type="text" id="fname" name="firstname">
          <input class="form-control" type="password" placeholder="Pass" type="text" id="pass" name="password" style="display:none">
       </div>
</div>
<a class="btn btn-flat flat-color btn-rounded" id="next_name">NEXT</a>
<button class="btn btn-flat flat-color btn-rounded" type="submit" id="submit" style="display:none">Submit</button>
<div>
   <!-- row-fluid -->                                    
</div>

//SCRIPT

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("#next_name").click(function(){
            $("#fname").hide('slow');
            $("#pass").show('fast');
            $("#next_name").hide();
            $("#submit").show();
            $("#submit").click(function(){
                var r=confirm("Login Confirmaition!!")
                if(r==true)
                {
                    //alert("asd");
                    var pass=$("#pass").val();
                    var fname=$("#fname").val();
                    //alert(pass);
                    //alert(fname);
                    $.post('server.php', {fname:fname, pass:pass, type:'passwordcheck'}, function(msg){
                        alert(msg);
                    });
                }
            });
        });
    });
</script> 

SERVER SIDE CODE
I tried to dump the data but the application is not reaching the server.php at all

<?php 
$type=$_POST['type'];
$fname=$_POST['fname'];
$pass=$_POST['pass'];
$data = {"name" : "Pramit", "password":"Pramit123"}
if($type=='passwordcheck'){
     $phpdata = json_decode($data, true);
     var_dump($phpdata);
     //exit;

     //return print($data);
}
?>


Source: ajax

Leave a Reply