Ramin K Ramin K - 4 months ago 8
Ajax Question

how to redirect the user to profile page after signing up using ajax call

Hello guys so basically the ajax code below checks for the username and email and makes sure that the user is repetitive and successfully inserts a record into the database. But the problem I am having is the part that says if data == true. I can't get the user to be redirected to their profile page. I mean after a user signs up, the signup form disappears and I am back to the index.php page however, it should redirect them to their profile page and signup and login buttons should disappear from my header.

var signupUNameBad = true;
var signupEmailBad = true;

// sign up button selected
$("#signup").submit(function(e) {
if (signupUNameBad == true){
alert("The User Name Selected is already in use, Please choose a different User Name");
if (signupEmailBad == true) {
alert("The Email is already in use on the system, Please choose a different email")
// add person to DB
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");


You're mixing PHP and JavaScript here:

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

You need to use JavaScript:

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