PHP not returning anything to ajax if class is instantiated
首先,抱歉标题,我不知道我要面对的问题是什么。 我会尽力解释。 我有一个php文件,它处理用户登录,如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | session_start(); if(isset($_POST['do_login'])) { require_once '../inc/mysql_connect.php'; $uname = $_POST['username']; $pass = $_POST['password']; $uname = strip_tags(mysqli_real_escape_string($con,trim($uname))); $pass = strip_tags(mysqli_real_escape_string($con, trim($pass))); $sql ="SELECT * from users where username='".$uname."'"; $select_data = mysqli_query($con,$sql)or die(mysqli_error()); if (mysqli_num_rows($select_data)>0) { $row = mysqli_fetch_array($select_data); $password_hash = $row['password']; $token = $row['token']; $email = $row['email']; $email_verified = $row['email_verified']; if (password_verify($pass,$password_hash)) { if ($email_verified > 0) { setcookie('token', $token, time()+31556926 ,"/","example.com", true, true); echo"success"; } else { echo"email_not_verified"; $_SESSION['email_not_verified'] ="true"; $_SESSION['username'] = $uname; $_SESSION['email'] = $email; $_SESSION['token'] = $token; } } else { echo"fail"; } exit(); } } |
我有一个js文件,它向文件发送请求:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | function do_login() { $("#btn-login").addClass('disabled'); var username=$("#emailid").val(); var pass=$("#password").val(); if(username!="" && pass!="") { $.ajax({ type:'post', url:'https://example.com/core/auth/do_login.php', data:{ do_login:"do_login", username:username, password:pass }, success: function (response) { if (response =="success") { $('#login').modal('hide'); window.location.href="https://example.com/account/"; } else if (response=="email_not_verified") { window.location.href="https://example.com/login" } else { shakeModal(); $("#btn-login").removeClass('disabled'); } } }); } return false; } |
它可以工作,但是如果我实例化像
您的代码可能会失败,因此永远不会调用
尝试在成功之下添加以下内容:阻止:
1 2 3 4 | error: function(xhr, error){ console.log(xhr); console.error(error); } |
我用它作为错误块的基础。