【发布时间】:2015-07-22 01:39:42
【问题描述】:
您好,我在提交表单后遇到重定向问题。 我正在使用简单的 ajax 表单在 div 中显示登录错误。
$(document).ready(function(){
$('#formlogin').on('submit', function (e) {
$.ajax({
type: 'POST',
url: 'login.php',
data: $(this).serialize(),
success: function(data) {
$('div#ack').empty().append(data);
}
});
e.preventDefault();
});
问题是提交成功后它没有重定向到“logged_in.php”
这里是php登录。
if (empty($username) === true || empty ($password) === true) {
$errors [] = 'Please enter both username and password!';
} else if (user_exists($username) === false) {
$errors [] = 'We can not find the name. Have you registered?';
} else {
$login = login($username, $password);
if ($login === false) {
$errors [] = 'This user name or password is incorrect.';
} else {
$_SESSION['user_id'] = $login;
header('Location: logged_in.php');
exit();
}
}
【问题讨论】:
-
感谢通过 ajax 序列化和发布表单的代码 - 正是我需要的,哦,重定向代码只是 window.location.href = "EditItem.php?batchid=" + bid + ""eitemid=NEW";
标签: javascript php jquery ajax forms