Button logic is now working

This commit is contained in:
Namonay
2024-09-29 01:09:34 +02:00
parent c7e9d5de5a
commit 95ce30c5a9
2 changed files with 31 additions and 2 deletions

View File

@ -66,6 +66,34 @@ header {
}
</style>
<script>
// JavaScript function to handle button click
document.addEventListener("DOMContentLoaded", function () {
const incidentBtn = document.getElementById("incident-btn");
incidentBtn.addEventListener("click", function () {
// Make a POST request to the /api/update route
fetch("/api/update", {
method: "POST",
headers: {
"Content-Type": "application/json"
}
})
.then(response => {
if (response.redirected) {
// If the request is successful and we are redirected
window.location.href = response.url;
} else {
alert("Error: Could not update the incident.");
}
})
.catch(error => {
console.error("Error:", error);
alert("An error occurred while updating the incident.");
});
});
});
</script>
<header>
<h1>ca42</h1>
</header>
@ -85,4 +113,4 @@ header {
</div>
</div>
<div id="incident-btn" form action>Incident</div>
<p class="btn-text">Note: Button doesn't actually work yet...</p>
<p class="btn-text">Note: Un accident par jour pour éviter la redondance</p>