fix availabilityJson post not working error: should pass CSRFToken into the function

This commit is contained in:
vinchent 2024-07-13 18:19:23 +02:00
parent 0f17b3405e
commit 5d670c1dc5
3 changed files with 4 additions and 4 deletions

View File

@ -124,7 +124,7 @@ function Prompt() {
}
}
function roomReservation(id) {
function roomReservation(id, csrfToken) {
document.getElementById("check-availability").addEventListener('click', () => {
let html = `
<form id="check-availability-form" action="/availability-json" method="post" novalidate class="needs-validation">
@ -158,7 +158,7 @@ function roomReservation(id) {
callback: (result) => {
const formElem = document.getElementById("check-availability-form");
let formData = new FormData(formElem);
formData.append("csrf_token", "{{.CSRFToken}}");
formData.append("csrf_token", csrfToken);
formData.append("room_id", id)
fetch('/availability-json', {

View File

@ -30,6 +30,6 @@
{{end}}
{{define "js"}}
<script>
roomReservation("1");
roomReservation("1", {{.CSRFToken}});
</script>
{{end}}

View File

@ -30,6 +30,6 @@
{{end}}
{{define "js"}}
<script>
roomReservation("2");
roomReservation("2", {{.CSRFToken}});
</script>
{{end}}