-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
44 lines (42 loc) · 1.51 KB
/
Copy pathscript.js
File metadata and controls
44 lines (42 loc) · 1.51 KB
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
34
35
36
37
38
39
40
41
42
43
44
var jwt = localStorage.getItem('token');
if (jwt != null) {
window.location.href = 'index.html';
}
function login() {
const name = document.getElementById('input-name').value;
const email = document.getElementById('input-email').value;
const message = document.getElementById('input-message')= document.getElementById('input-email').value;
const xhttp = new XMLHttpRequest();
xhttp.open('POST', 'http://acril-backend.herokuapp.com/api/v1/feedback/add');
xhttp.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
xhttp.send(JSON.stringify({
'name': name,
'email': email,
'message': message
}));
xhttp.onreadystatechange = function () {
if (this.readyState == 4) {
const objects = JSON.parse(this.responseText);
console.log(objects);
if (objects['status'] == 'ok') {
localStorage.setItem('token', objects['token']);
Swal.fire({
text: objects['message'],
icon: 'success',
confirmButtonText: 'OK'
}).then((result) => {
if (result.isConfirmed) {
window.location.href = 'index.html';
}
});
} else {
Swal.fire({
text: objects['message'],
icon: 'error',
confirmButtonText: 'OK'
});
}
}
};
return false;
}