added orai
This commit is contained in:
54
24_10_15/fetch.js
Normal file
54
24_10_15/fetch.js
Normal file
@@ -0,0 +1,54 @@
|
||||
let url = "https://jsonplaceholder.typicode.com/photos";
|
||||
|
||||
|
||||
|
||||
document.getElementById("lekeres").addEventListener("click", function () {
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
for (let index = 0; index < 3; index++) {
|
||||
let cim = document.createElement("h2");
|
||||
cim.innerHTML = data[index].title;
|
||||
|
||||
let element = document.createElement("img");
|
||||
element.src = data[index].thumbnailUrl;
|
||||
|
||||
let divelement = document.getElementById(`img_${index}`);
|
||||
divelement.appendChild(cim);
|
||||
divelement.appendChild(element);
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
.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