Reputation: 312
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 use to logout of a chat window, that is ran using AJAX. I'm just wondering if there is a way so it will do a redirect when the button is pressed. This is the procedure that is ran on.click. I've currently experimented with window.location.
but that doesn't seem to do the trick.
How would I do this?
Upvotes: 0
Views: 1458
Reputation: 14681
If it's an Ajax call you cannot redirect the user. If you use header('Location: ...')
you will redirect the Ajax requestion, which will have no effect on the user.
You can either:
header('Location: ...')
to send him back to your home pagewindow.location
must be done in the javascript par after the ajax call. In the onSuccess
event for instanceUpvotes: 1