From 464230982db2e5726da3eda16b2ad8029366dfcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kov=C3=A1cs=20Rudolf?= Date: Mon, 9 Nov 2026 09:23:52 +0100 Subject: [PATCH] =?UTF-8?q?K=C3=A9pek=20=C3=A9s=20Tailwind?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dom/posts.js | 36 +++++++++++++++++++++++++++++++----- rest_photos/index.html | 16 ++++++++++++++++ rest_photos/photos.js | 27 +++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 rest_photos/index.html create mode 100644 rest_photos/photos.js diff --git a/dom/posts.js b/dom/posts.js index e7de735..c169bf2 100644 --- a/dom/posts.js +++ b/dom/posts.js @@ -13,13 +13,39 @@ keres.onload=function(){ } -keres.send(); +//keres.send(); console.log(valasz); -fetch('https://jsonplaceholder.typicode.com/posts') -.then(res=>res.json()) -.then(adat=>console.log(adat)) -.catch(error=>console.log(error)); +//Kérések fajtái: GET, POST, PUT, PATCH, DELETE, OPTIONS +// fetch('https://jsonplaceholder.typicode.com/posts') +// .then(res=>res.json()) +// .then(adat=>console.log(adat)) +// .catch(error=>console.log(error)); + +//async await + +async function letolt() { + try { + let keres=await fetch('https://jsonplaceholder.typicode.com/posts'); + let valasz=await keres.json(); + + console.log(valasz); + valasz.forEach(post => { + let p=document.createElement('p'); + let body=document.createElement('p'); + body.textContent=post.body; + p.textContent=post.title; + root.appendChild(p); + root.appendChild(body); + }); + + } catch (error) { + alert(error); + } + +} + +letolt(); \ No newline at end of file diff --git a/rest_photos/index.html b/rest_photos/index.html new file mode 100644 index 0000000..d36931b --- /dev/null +++ b/rest_photos/index.html @@ -0,0 +1,16 @@ + + + + + + + + Képek letöltése + + +

Képek letöltése

+
+ +
+ + \ No newline at end of file diff --git a/rest_photos/photos.js b/rest_photos/photos.js new file mode 100644 index 0000000..3a7ba06 --- /dev/null +++ b/rest_photos/photos.js @@ -0,0 +1,27 @@ +let root=document.getElementById('root'); + +let kontener=document.createElement('div'); +kontener.setAttribute('class','flex flex-row flex-wrap items-center justify-center bg-sky-200'); + +fetch('https://jsonplaceholder.typicode.com/photos') +.then(res=>res.json()) +.then(kepek=>{ + kepek.forEach(kep => { + let kepKontener=document.createElement('div'); + kepKontener.setAttribute('class','flex flex-col items-center justify-center bg-sky-400 m-2 p-2 rounded-xl w-96'); + let title=document.createElement('p'); + title.setAttribute('class','text-2xl text-center font-bold text-sky-600'); + title.textContent=kep.title; + + let image=document.createElement('img'); + image.setAttribute('class','rounded-xl'); + image.src=kep.url; + kepKontener.appendChild(image); + kepKontener.appendChild(title); + kontener.appendChild(kepKontener); + }); + +}) +.catch(err=>alert(err)); + +root.appendChild(kontener); \ No newline at end of file