Ajax logout redirection
public static function logout(){
DB::query("DELETE FROM webchat_users WHERE name = '".DB::esc($_SESSION['user']['name'])."'");
$_SESSION = array();
unset($_SESSION);
return array('status' => 1);
window.location.replace("http://domain.com/index.php");
}
This is the code I am using to log out of the chat window, which is triggered using AJAX. I'm just wondering if there is a way so it will redirect when the button is clicked. This is the procedure performed by on.click. I am currently experimenting with window.location.
, but it doesn't seem like a trick.
How should I do it?
0
source to share
1 answer
If this is an Ajax call, you cannot redirect the user. If you are using header('Location: ...')
you will redirect the Ajax request which will not affect the user.
You can:
- redirect the user to a logout page instead of sending an Ajax request and use
header('Location: ...')
to send it to your home page. - Use ajax call, but
window.location
must be done in javascript par after ajax call. For example, in the eventonSuccess
+1
source to share