I am making a logout button which calls a PHP script via an AJAX call but somehow my php is not redirecting. Also when I try to use javascript it doesnt work either.
I tried the following things:
- Adding
ob_start()andob_end_flush() - Changing
exit;toexit(); - Changing
header("Location: http://localhost/page_login.html)toecho("<script>location.href = http://localhost/page_login.html';</script>");
When I open the php script directly in my URL (by just typing it in) it redirects me to the page.login.html however from the ajax call its not. When I print the data it prints the page_login.html file which also excludes the option that its not in the correct map.
Anyone any ideas on how to fix this?
HTML
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div id="logout_button">
Logout
</div>
<script src="jquery-3.2.1.js"></script>
<script src="logout.js" type="text/javascript"></script>
</body></html>
JAVASCRIPT (logout.js)
$('#logout_button').click(function(){
$.ajax({
type: 'POST',
url: 'logout.php',
error: function(response) { console.log(JSON.stringify(response))},
success: function(data){
console.log(data);
}
});
})
PHP (logout.php)
<?php
header('Location: http://localhost/page_home.html');
exit;
?>
.phpextension? What are you using to maintain the user session? I see nosession_startnor anything to teardown the session inlogout.phpAlso- thelogoutpage is not sending a response so the ajax callback is never going to do anything as suchmethod="POST"andaction="logout.php"