php - AJAX not running success function -


i've got ajax script lets user login on login page script seems stop after runs beforesend.

<script>     $(document).ready(function()      {         $('#login').click(function() {             var username=$("#username").val();             var password=$("#password").val();             var datastring = 'username='+username+'&password='+password;             if($.trim(username).length>0 && $.trim(password).length>0) {                 $.ajax({                     type: "post",                     url: "login.php",                     data: datastring,                     cache: false,                     beforesend: function(){                                                                                                                 $("#login").val('connecting...');                     },                     success: function(data){                         if(data) {                             $("body").load("<?php echo $dom; ?>").hide().fadein(1500).delay(6000);                             window.location.href = "<?php echo $dom; ?>";                         } else {                             $('#shakeme').shake();                             $("#login").val('login')                             $("#error").html("<span style='color:#cc0000'>error:</span> invalid username , password. ");                         }                     }                 });             } return false;          });     }); </script> 

the ajax script sends data login.php

if(isset($_post['username']) && isset($_post['password'])) {     $username=clean($_post['username']);      $password=clean($_post['password']));      $sql = "select password user username='" . $username . "'";     $result = $conn->query($sql)->fetch_assoc();     $pass = $result['password'];     $salt = getsalt($pass);     $password = $salt . $password;     $password = $salt . hash('sha256', $password);     if(strcmp($pass,$password)==0) {         $_session['login_user']=$username;     } } 

am doing wrong php script? meant return data somehow? first time using ajax.

you need return values login.php file as

login.php

if(strcmp($pass,$password)==0) {      $_session['login_user']=$username;      echo true; }else{      echo false; } exit; 

and within js

success: function(data){ if (data == true) {     $("body") . load("<?php echo $dom; ?>") . hide() . fadein(1500) . delay(6000);     window.location.href = "<?php echo $dom; ?>"; } else {     $('#shakeme') . shake();     $("#login").val('login')     $("#error") . html("<span style='color:#cc0000'>error:</span> invalid username , password. "); } } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -