Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在下面的情况下,如何使用jqueryajax指向另一个页面?_Php_Jquery - Fatal编程技术网

Php 在下面的情况下,如何使用jqueryajax指向另一个页面?

Php 在下面的情况下,如何使用jqueryajax指向另一个页面?,php,jquery,Php,Jquery,我有一个php脚本,可以通过用户的电子邮件和密码验证用户,如果它无效,我的脚本会回显“无法登录”之类的内容,如果成功,它将指向另一个页面,我该如何做 以下是我的php代码: if(isset($_POST['email'])&&isset($_POST['password'])){ $email = $_POST['email']; $password = $_POST['password']; $result = userAuthentication(

我有一个php脚本,可以通过用户的电子邮件和密码验证用户,如果它无效,我的脚本会回显“无法登录”之类的内容,如果成功,它将指向另一个页面,我该如何做

以下是我的php代码:

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还是那个?:)谢谢