服务器端后,阿贾克斯提交:刷新页面 - 记录在
<?php
if (empty($_POST) === false){
$username = $_POST['username'];
$password = $_POST['password'];
if (empty($username) === true || empty($password) === true){
$errors[] = 'You need to enter a username or password';
}
else if (user_exists($username)===false){
$errors[] = 'We can\'t find that username in our database.';
}
else if (user_active($username) === false){
$errors[] = 'Activate your account.';
} else {
$login = login($username,$password);
if ($login === false){
$errors[] = 'Incorrect combination.';
} else {
$_SESSION['user_id'] = $login;
$errors[] = 'success';
}
}
}else {
$errors[] = 'No data received!';
}
output_errors($errors);
?>
阿贾克斯:
$(document).ready(function(){
$("#login").click(function(){
$.post($('#loginform').attr("action"), $('#loginform').serializeArray(), function(data) {
if(data == 'success'){
$(document).ajaxStop(function() { location.reload(true); });
}else {
$('#loginmsg').html(data);
}
});
});
});
的问题是,它不识别“数据”当我把它放在if语句。登录没有问题,但页面不刷新。请帮忙。谢谢。
更新:我试图没有AjaxStop的位置重新加载,但它没有奏效。我想要的是刷新只有当它是一个“成功”
当你做console.log(data)时,你会看到什么;如果条件... –
我得到的回应消息从基于笏im进入输入框中的PHP – Yoosuf