我有一个注册页面,我想通过 ajax 请求将用户重定向到登录页面。但是,这个特定的 ajax 请求会进行重定向,但不会在 POST 请求之后传递会话
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";
}
});
登录/添加功能通过 POST 请求获取值,然后将这些值放入会话中并进行重定向。在普通的 php/CI 中,如果没有 ajax 请求,同样的事情也会完美地发生。但是,不是通过 ajax 请求发生的。
如果有帮助,这是php代码
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);
}