added orai
This commit is contained in:
34
24_10_14/fetch.js
Normal file
34
24_10_14/fetch.js
Normal file
@@ -0,0 +1,34 @@
|
||||
let url = "https://jsonplaceholder.typicode.com/users/";
|
||||
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
document.getElementById("username").innerHTML += data[2].name;
|
||||
document.getElementById("email").innerHTML += data[1].email;
|
||||
})
|
||||
.catch(data => console.log(data));
|
||||
|
||||
// post
|
||||
let path = "response.json";
|
||||
fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
name: "Példa Péter",
|
||||
email: "pelda_peter@gmail.com"
|
||||
}),
|
||||
}).then(response => response.json()).then(data => console.log(data));
|
||||
|
||||
//PUT
|
||||
fetch(url, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
name: "Példa Péter",
|
||||
email: "pelda_peter@gmail.com"
|
||||
}),
|
||||
}).then(response => response.json()).then(data => console.log(data));
|
||||
Reference in New Issue
Block a user