-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tmpl
37 lines (37 loc) · 1.38 KB
/
index.tmpl
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
const comment = document.querySelector('#comment')
const all = document.querySelector('#all_comments')
const url = `${ api_dns }`
function send_comment(){
fetch(`${ api_dns }`+'/comment',{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
mode: 'cors',
body: JSON.stringify({comment: comment.value})
}).then(res=>{
return res.json()
})
.then(data=>{
console.log(data)
})
}
function get_all(){
all.innerText = ''
fetch(`${ api_dns }`+'/all_comments',{
method: 'GET',
headers: {
'Content-Type': 'application/json'
},
mode: 'cors',
}).then(res=>{
return res.json()
})
.then(data=>{
data.map(el=>{
let e = document.createElement('p')
all.append(el.comment, e)
})
})
}
setInterval(()=>{get_all()},1000)