fix availabilityJson post not working error: should pass CSRFToken into the function
This commit is contained in:
		@ -124,7 +124,7 @@ function Prompt() {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function roomReservation(id) {
 | 
					function roomReservation(id, csrfToken) {
 | 
				
			||||||
    document.getElementById("check-availability").addEventListener('click', () => {
 | 
					    document.getElementById("check-availability").addEventListener('click', () => {
 | 
				
			||||||
        let html = `
 | 
					        let html = `
 | 
				
			||||||
                <form id="check-availability-form" action="/availability-json" method="post" novalidate class="needs-validation">
 | 
					                <form id="check-availability-form" action="/availability-json" method="post" novalidate class="needs-validation">
 | 
				
			||||||
@ -158,7 +158,7 @@ function roomReservation(id) {
 | 
				
			|||||||
            callback: (result) => {
 | 
					            callback: (result) => {
 | 
				
			||||||
                const formElem = document.getElementById("check-availability-form");
 | 
					                const formElem = document.getElementById("check-availability-form");
 | 
				
			||||||
                let formData = new FormData(formElem);
 | 
					                let formData = new FormData(formElem);
 | 
				
			||||||
                formData.append("csrf_token", "{{.CSRFToken}}");
 | 
					                formData.append("csrf_token", csrfToken);
 | 
				
			||||||
                formData.append("room_id", id)
 | 
					                formData.append("room_id", id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                fetch('/availability-json', {
 | 
					                fetch('/availability-json', {
 | 
				
			||||||
 | 
				
			|||||||
@ -30,6 +30,6 @@
 | 
				
			|||||||
{{end}}
 | 
					{{end}}
 | 
				
			||||||
{{define "js"}}
 | 
					{{define "js"}}
 | 
				
			||||||
<script>
 | 
					<script>
 | 
				
			||||||
roomReservation("1");
 | 
					roomReservation("1", {{.CSRFToken}});
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
{{end}}
 | 
					{{end}}
 | 
				
			||||||
 | 
				
			|||||||
@ -30,6 +30,6 @@
 | 
				
			|||||||
{{end}}
 | 
					{{end}}
 | 
				
			||||||
{{define "js"}}
 | 
					{{define "js"}}
 | 
				
			||||||
<script>
 | 
					<script>
 | 
				
			||||||
    roomReservation("2");
 | 
					roomReservation("2", {{.CSRFToken}});
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
{{end}}
 | 
					{{end}}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user