-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfun.js
More file actions
58 lines (55 loc) · 1.64 KB
/
fun.js
File metadata and controls
58 lines (55 loc) · 1.64 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function addc(){
const rno=document.getElementById("roll").value;
const confe=document.getElementById("con").value;
const condata= {
"roll_no": rno,
"confession": confe
};
document.getElementById('roll').value='';
document.getElementById('con').value='';
fetch("https://tpcconfessions.onrender.com/api/postConfession", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(condata),
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(myconfession => {
console.log('New User Data:', myconfession);
})
.catch(error => {
console.error('Error:', error);
});
}
function getc(){
const rollno=document.getElementById("rolln").value;
const rnos = {
"roll_no": rollno,
};
const myrno = new URLSearchParams(rnos).toString();
const myurl=`${"https://tpcconfessions.onrender.com/api/getConfession"}?${myrno}`;
document.getElementById('rolln').value='';
fetch(myurl)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(confessions => {
var connie=""
for (let i = 0; i < confessions.length; i++) {
connie += (i+1)+") " + confessions[i].confession + "<br>";
}
document.getElementById("conff").innerHTML=connie
})
.catch(error => {
console.error('Error:', error);
});
}