Php 在下面的情况下,如何使用jqueryajax指向另一个页面?
我有一个php脚本,可以通过用户的电子邮件和密码验证用户,如果它无效,我的脚本会回显“无法登录”之类的内容,如果成功,它将指向另一个页面,我该如何做 以下是我的php代码:Php 在下面的情况下,如何使用jqueryajax指向另一个页面?,php,jquery,Php,Jquery,我有一个php脚本,可以通过用户的电子邮件和密码验证用户,如果它无效,我的脚本会回显“无法登录”之类的内容,如果成功,它将指向另一个页面,我该如何做 以下是我的php代码: if(isset($_POST['email'])&&isset($_POST['password'])){ $email = $_POST['email']; $password = $_POST['password']; $result = userAuthentication(
if(isset($_POST['email'])&&isset($_POST['password'])){
$email = $_POST['email'];
$password = $_POST['password'];
$result = userAuthentication($email,$password);
if($result == false){
echo 'Unable to login';
}
else if($result == true){
header("location: success.php");
}
}
以下是我的js代码:
$(function() {
$("button").button();
$("#clickme").click(function(){
$.post("check.php", {
"email": $("#txtEmail").val(),
"password": $("#txtPassword").val()
},
function(msg){
$(".message").html(msg);
});
return false;
});
});
您不能像那样从PHP重定向。您可以从javascript返回成功消息并重定向:
$(function() {
$("button").button();
$("#clickme").click(function(){
$.post("check.php", {
"email": $("#txtEmail").val(),
"password": $("#txtPassword").val()
},
function(msg){
$(".message").html(msg);
if(msg == 'success'){
window.location = 'success.php';
}
});
return false;
});
});
php:
javascript:
$(function() {
$("button").button();
$("#clickme").click(function(){
$.post("check.php", {
"email": $("#txtEmail").val(),
"password": $("#txtPassword").val()
},
function(msg){
$(".message").html(msg);
if(msg == 'success'){
window.location = 'success.php';
}
});
return false;
});
});
do it client-side:
document.location.replace(新位置)
哪个更适合使用window.location还是那个?:)谢谢