php - jQuery Form Validation redirect if success validation -


i have jquery login form function check user validation.

here js :

$(document).ready(function()     {         $('#button_sign_in').click(function(){              console.log('login');             $.ajax({                 url: "login",                 type: "post",                 data: $('#login_form').serialize(),                 success: function (data) {                     //console.log('data:'+data);                     if (data.user) {                         $('#lblusername').text(data.user.username);                     }                     else {                         $('#button_sign_in').shake(4,6,700,'#cc2222');                         $('#username').focus();                     }                 },                 error: function (e) {                     console.log('error:'+e);                 }             });         });     }); 

the logic is, if wrong username or password button shake. if correct login redirect home page.

and here php function :

require ("functions/_db_.php");  $username = $_post['username']; $password = $_post['password'];  $query = mysql_query("select username, password t_users username='$username' && password='$password'"); $found = mysql_num_rows($query); if ($found > 0) {     header('location:home.php'); } 

now problem : if login corrected, page won't redirect home page.

any suggestions ?

keep php script bellow

        //check inputs against mysql injections         $username = mysql_real_escape_string($_post['username']);          $password = mysql_real_escape_string($_post['password']);          $query = mysql_query("select username, password t_users username='$username' && password='$password'");         $found = mysql_num_rows($query);           if ($found > 0)         {             $res='success';         }         else         {             $res='error';         }          $ary=array("status"=>$res);          echo json_encode($ary); //json output - sending assynchronus data in json format 

and script

$.ajax ({     url: "login",     type: "post",     data: $('#login_form').serialize(),     datatype:'json', //we need ajax data in json type     success: function (data)      {         if (data.status=='success') //status proper of json object, gave in php code in above script         {             window.location='home.php';          }         else          {             $('#button_sign_in').shake(4,6,700,'#cc2222');             $('#username').focus();         }     },     error: function (e) {         console.log('error:'+e);     } }); 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -