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

View File

@ -43,7 +43,20 @@
</div>
</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>
{{end}}