我使用Ion Auth在CodeIgnitor中运行身份验证,似乎是一个很棒的库,具有我需要的所有功能。但我想使用jQuery创建一个AJAX登录。当javascript存在或不存在时,基本上是为了增强功能/降级。
我不知道如何做到这一点,以便在Ion Auth检查登录状态的后续页面上它将全部正常工作。
这是我到目前为止所拥有的:
-
public function js_login() { if( $this->ion_auth->login($this->input->post('identity'), $this->input->post('password'), $this->input->post('remember'))) { $result = "Login Details Correct"; } else { $result = "Login Details incorrect"; } $array = array( "result" => $result ); echo json_encode($array); }
-
$("#login").submit(function(event) { event.preventDefault(); $.post( "/auth/js_login", $(this).serialize(), function(data){ // Set the cookie somehow alert(data.result); }, "json"); });
-
所以我基本上需要知道如何获取通常由Ion Auth设置的会话数据并使用jQuery设置它。之后我可以重定向到相应的页面。
答案 0 :(得分:0)
使用PHP(在js_login函数中)登录成功时执行会话设置,然后重定向用户。它会在下一页自动生效。