这是我所做的 AJAX 登录。
$(function() {
$('#loginform').submit(function(){
var uname = $('#username').val();
var password = $('#password').val();
$("#loading").show();
$("#loading").fadeIn(400);
$.POST('php/authorization.php', (username: uname, password: password),
function(asd) {
if(asd.success){
location.href = asd.redirect;
}else{
$('.error').html(asd.message);
};
}, 'json');
return false;
});
});
和 PHP 代码段
if($data = mysql_fetch_assoc($raw))
{
$_SESSION['loggedin'] = true;
$_SESSION['uid'] = $data['u_id'];
$_SESSION['uname'] = $data['u_name'];
$_SESSION['utype'] = $data['u_type'];
$_SESSION['uactive'] = $data['u_active'];
mysql_close($link);
$asd['success'] = true;
$asd['redirect'] = '../dashboard.php';
}
else
{
mysql_close($link);
$asd['success'] = false;
$asd['message'] = "Wrong username or password";
}
echo json_encode($asd);
问题是,PHP 不是重定向或执行任何操作,{"success":true,"redirect":"..\/dashboard.php"}
而是打印。
为什么?提前致谢。