Sending & processing an AJAX request

This commit is contained in:
Muyao CHEN 2024-06-30 16:23:12 +02:00
parent 97b9898dfc
commit e18849331c
2 changed files with 23 additions and 5 deletions

View File

@ -177,14 +177,13 @@
title = "", title = "",
} = c; } = c;
const {value: formValues} = await Swal.fire({ const {value: result} = await Swal.fire({
title: title, title: title,
html: msg, html: msg,
backdrop: false, backdrop: false,
focusConfirm: false, focusConfirm: false,
showCancelButton: true, showCancelButton: true,
willOpen: () => { willOpen: () => {
console.log("test")
const elem = document.getElementById('reservation-dates-modal') const elem = document.getElementById('reservation-dates-modal')
const rp = new DateRangePicker(elem, { const rp = new DateRangePicker(elem, {
"format": "yyyy-mm-dd", "format": "yyyy-mm-dd",
@ -205,8 +204,14 @@
}, },
}) })
if (formValues) { if (c.callback !== undefined) {
Swal.fire(JSON.stringify(formValues)) if (result &&
result.dismiss !== Swal.DismissReason.cancel &&
result !== "") {
c.callback(result);
} else {
c.callback(false);
}
} }
} }

View File

@ -43,7 +43,20 @@
</div> </div>
</form> </form>
`; `;
Prompt().custom({title: "Choose your dates", msg: html}) Prompt().custom({
title: "Choose your dates",
msg: html,
callback: (result) => {
console.log(result);
fetch('/availability-json')
.then(response => response.json())
.then(data => {
console.log(data);
})
},
});
}); });
</script> </script>
{{end}} {{end}}