-
Notifications
You must be signed in to change notification settings - Fork 3
/
cancel.js
33 lines (24 loc) · 940 Bytes
/
cancel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { server } from './utils.js'
const sendFormData = () => {
var xhr = new XMLHttpRequest();
xhr.open("POST", `${server}/booking/cancel`);
// This fires up when the connection is successful
xhr.onload = function(event) {
localStorage.setItem('response', xhr.response)
console.log(xhr.response)
var statusMessage = JSON.parse(xhr.response).status
if (xhr.status == 200) {
alert(statusMessage)
window.location.href = 'dashboard.html'
} else {
alert("Oops! Something went wrong!")
}
};
var form = document.getElementById("cancel-ticket")
var formData = new FormData(form);
var res = localStorage.getItem('response')
var token = JSON.parse(res).token
xhr.setRequestHeader('Authorization', token)
xhr.send(formData);
}
document.getElementById('submit').addEventListener('click', sendFormData)