0

I know that the question is a bit confusing but here is the case.

I have the following Ajax function:

    $.ajax({
    url:"../controllers/xx_register.php",
    type:"POST",
    data:send,
    success: function(response){
        if (response=="1") {
            window.location.replace("http://localhost/Underground/01.InProgress/ES-dictionary/public/index.php");
            return true;
        }
        else{
            $('#error').append(response);
        }
    },
    error: function(){
        $('#error').append('Fatal error!');
    }       
});
return false;

the xx_register.php file:

$arr=$_POST;

$reg = registerMe($arr);

if ($reg === true) {
    $_SESSION['is_logged']=$arr['username'];
    echo 1;
    exit();
}   
else{
    echo($reg);
    exit();
}

finally the index.php

    session_start();

if (isset($_SESSION['is_logged'])) {
    header("Location: ../views/start.php");
    exit();
    }
else{
    header("Location: ../views/login.php");
    exit();
}

Shortly - the idea: I use ajax function for registering a new users. If everything is ok with the registration the user will be redirected to index.php. As the $_SESSION['is_logged'] exist the user will be redirected to the start.php page.

This all works for FireFox 21, IE 10, Safari 5.1 but on Chrome 27 the thing are quite different - the user is again redirected to loggin.php. The simple logic is pointing that window.location.replace is redirecting to index.php and clearing the session. I really don't see any explanation. Two questions: 1. Am I correct about the issue with the window.location.replace? 2. How to fix it?

Thanks a lot.

4

1 回答 1

1

Don't use .replace() for this, just assign the value directly.

This is fix:

window.location = "http://localhost/Underground/01.InProgress/ES-dictionary/public/index.php";
于 2013-06-27T14:11:52.780 回答