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 @@ + + +
+ + + + +