-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
30 lines (26 loc) · 742 Bytes
/
index.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
// Add your code here
const body = document.querySelector('body')
function submitData (name, email) {
return fetch ('http://localhost:3000/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json'
},
body: JSON.stringify({
name: name,
email: email
})
})
.then (res => res.json())
.then (function(userObj) {
const div = document.createElement('div')
div.textContent = userObj.id
body.appendChild(div)
})
.catch (function() {
const li = document.createElement('li')
li.textContent = 'Unauthorized Access'
body.appendChild(li)
})
}