|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() { |
|
|
|
|
|
function handleLogout() { |
|
|
fetch('logout.php', { |
|
|
method: 'POST' |
|
|
}) |
|
|
.then(response => response.json()) |
|
|
.then(data => { |
|
|
if (data.success) { |
|
|
window.location.href = 'pages/home.php'; |
|
|
} else { |
|
|
alert(data.message); |
|
|
} |
|
|
}) |
|
|
.catch(error => console.error('Error:', error)); |
|
|
} |
|
|
|
|
|
|
|
|
const logoutButton = document.getElementById('logout-button'); |
|
|
if (logoutButton) { |
|
|
logoutButton.addEventListener('click', function(e) { |
|
|
e.preventDefault(); |
|
|
handleLogout(); |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
}); |