-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch-api.js
More file actions
31 lines (27 loc) · 797 Bytes
/
fetch-api.js
File metadata and controls
31 lines (27 loc) · 797 Bytes
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
const newPost = {
userId: 1,
title: "YENİ BAŞLIK",
body: "MERHABA LOREM MERHABA !!"
}
document.querySelector("button").addEventListener('click', ()=>{
fetch("https://jsonplaceholder.typicode.com/posts",{
method : "post",
body: JSON.stringify(newPost),
headers : {"Content-type" : "application/json"}
})
.then(response =>response.json())
.then(json =>{
console.log(json);
})
.catch(err => console.log(err))
})
// Kendi kaynağınızdan veri çekme
/*
document.querySelector("button").addEventListener('click', ()=>{
fetch("poem.txt")
.then(response =>response.text())
.then(text =>{
console.log(text);
})
.catch(err => console.log(err))
})*/