使用AJAX调用注册后,如何将用户重定向到配置页面



您好,大家好,因此基本上AJAX代码检查了用户名和电子邮件的检查,并确保用户重复并成功地将记录插入数据库中。但是我遇到的问题是说data == true的部分。我无法将用户重定向到他们的个人资料页面。我的意思是,用户注册后,注册表格消失了,我又回到index.php页面,但是,它应该将其重定向到他们的个人资料页面,并且注册和登录按钮应从我的标题中消失。

var signupUNameBad = true;
var signupEmailBad = true;
// sign up button selected
$("#signup").submit(function(e) { 
$("#signup").css('visibility','hidden')
e.preventDefault();
if (signupUNameBad == true){
    alert("The User Name Selected is already in use, Please choose a different User Name");
    return;
}
if (signupEmailBad == true) {
    alert("The Email is already in use on the system, Please choose a different email")
    return;
}
else
// add person to DB
$.ajax({
    url: 'enterUserBasic.php',
    type: 'post',
    dataType: 'text',
    async: 'false',
    data: "fname=" + $("#Sfname").val() + "&lname="+ $("#Slname").val() + "&pass=" + $("#Spass").val() + "&uName=" + $("#signupUserName").val() + "&email=" + $("#signupEmail").val(),  
    success: function (data) { 
        // if data = true then the user was added, false the user was declined for some reason
        if (data == "true") {
            header('location: profile.php');
        }
        else if (data == "false"){
            alert("database error, please try again");
        }
    },
       error: function (data) {
           alert("Some kind of error occured in login, please try again");
       }
    });
});

您在这里混合PHP和JavaScript:

 if (data == "true") {
     header('location: profile.php'); // PHP code will not work here
 }

您需要使用JavaScript:

 if (data == "true") {
    window.location = "profile.php";
 }

最新更新