“我正在尝试修复此重定向,任何人都可以帮助我解决此代码的错误”
我希望ajax发布上的成功进入个人资料页面。由于某种原因,我一直做错了。知道该怎么做才能解决这个问题吗?
<?php
session_start();
include 'includes/config.php';
$code = mysqli_real_escape_string($db,$_POST['code']);
$results = mysqli_query($db,"SELECT * FROM students WHERE code='$code'");
if (mysqli_num_rows($results) == 1 ) {
$_SESSION['code'] = $code;
echo ('login');
}
else {
echo "not login";
}
?>
<?php include 'includes/nav.php';
session_start();
?>
<script>
$(document).ready(function () {
$('.forms').submit(function (e) {
e.preventDefault();
$.ajax({
type: "POST",
url: 'login.php',
data: $(this).serialize(),
success: function (data) {
if (data === 'login') {
location.href = 'profile.php';
}
else {
alert(data);
}
}
});
});
});
</script>
<form action="login.php" method="POST" class="forms">
<div class="form-group">
<input name="code" type="text" placeholder="enter your code">
<button type="submit" name="studentSubmit" class="btn btn-dark">login</button>
</div>
</form>