-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.js
74 lines (56 loc) · 2.05 KB
/
delete.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
let ul = document.querySelector('#users');
let ID = [];
function deleteUser(email){
document.getElementById(email).remove();
for( let a = 0; a < ID.length; a++ ){
if( ID[a].Email === email) {
axios.delete(`https://crudcrud.com/api/b389c9876b6145edbb24c1ab6e3bda83/appointmentData/${ID[a]._id}`)
.catch(err => console.log(err))
}
}
}
function displayData(obj) {
childHTML=`<li id=${obj.Email}>${obj.Name} - ${obj.Email} - ${obj.Phone}
<button onclick=deleteUser('${obj.Email}')>Delete User</button>
</li>`;
ul.innerHTML += childHTML;
// let li = document.createElement('li');
// li.appendChild(document
// .createTextNode(`${obj.Name} - ${obj.Email} - ${obj.Phone}`));
// ul.appendChild(li);
// li.style.listStyleType = 'disc';
}
window.addEventListener('DOMContentLoaded', () => {
axios.get("https://crudcrud.com/api/b389c9876b6145edbb24c1ab6e3bda83/appointmentData")
.then(response => {
for (let a = 0; a < response.data.length; a++) {
displayData(response.data[a]);
ID.push(response.data[a]);
}
})
.catch(err => console.log(err));
// console.log(ID);
})
function getDetails(event) {
event.preventDefault();
let Name = document.querySelector('#name').value;
let Email = document.querySelector('#mail').value;
let Phone = document.querySelector('#phone').value;
let obj = {
Name,
Email,
Phone
}
axios
.post('https://crudcrud.com/api/b389c9876b6145edbb24c1ab6e3bda83/appointmentData', obj)
.then(response => {
displayData(response.data);
})
.catch(err => {
document.body.innerHTML += '<h4>Something went wrong.</h4>';
console.log(err);
})
document.querySelector('#name').value = '';
document.querySelector('#mail').value = '';
document.querySelector('#phone').value = '';
}