I have a register page in which via ajax request i want to redirect the user to the logged in page. But, this particular ajax request does a redirect but doesn't pass on the session after the POST request
var dataString = 'name='+ name + '&email=' + email1 + '&password=' + password1;
//alert (dataString);return false;
$.ajax({
type: "POST",
url: "http://localhost/ci/index.php/login/add/",
data: dataString,
success: function() {
window.location.href = "http://localhost/ci/dashboard";
}
});
The login/add function is taking the values via POST request which then puts these value in session and does a redirect. The same thing is happening perfectly without a ajax request in plain php/CI. But, not happening via ajax request.
Here's the php code if it helps
if ($this->input->post("add") == "Sign up") {
$data_array = array(); //this array contains post data
$output = $this->user_model->add_new($data_array);
if($output == TRUE){
$this->session->set_userdata('logged_in', '1');
}
$data = array(
'name' => form_error('name'),
'email' => form_error('email'),
'password' => form_error('password')
);
echo json_encode($data);
}