added orai

This commit is contained in:
szabomarton
2024-10-14 13:15:57 +02:00
parent 6dc5052873
commit 71a97bc404
5 changed files with 104 additions and 0 deletions

34
24_10_14/fetch.js Normal file
View 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));