-
Notifications
You must be signed in to change notification settings - Fork 0
/
lecture_46.js
35 lines (30 loc) · 1.04 KB
/
lecture_46.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
//...................................Fetch_Api...............................................
const fetchbtn =document.getElementById("fetchData")
const backupbtn =document.getElementById("backupData")
fetchbtn.addEventListener("click",fetchdata)
backupbtn.addEventListener("click",backupdata)
//....................Get request.................
function fetchdata(){
console.log("hey u click on fetch btn");
url = "https://jsonplaceholder.typicode.com/todos/1"
fetch(url).then((Response)=>{
return Response.json();
}).then((data)=>{
console.log(data);
})
}
//..................Post request........................
function backupdata() {
url =" https://jsonplaceholder.typicode.com/todos/1"
data ={"userId":"suraj1218310","id":"123","title":"this is suraj sharma","body":"this is inside"}
params ={
method : "post",
headers: {
"content-type":"application/json"
},
body: data
}
fetch(url).then(response=> response.json())
.then(data=> console.log(data)
)
}