diff --git a/rest/fetch.js b/rest/fetch.js new file mode 100644 index 0000000..d468b5e --- /dev/null +++ b/rest/fetch.js @@ -0,0 +1,25 @@ + +// fetch('https://jsonplaceholder.typicode.com/posts') +// .then(res=>res.json()) +// .then(adatok=>console.log(adatok)) +// .catch(err=>console.log(err)) + + + + + +async function letolt() { + try { + let keres=await fetch('https://jsonplaceholder.typicode.com/posts/1'); + let valasz=await keres.json(); + + console.log(valasz); + + } catch (error) { + console.log(error); + } +} + +letolt(); + +console.log("Valami"); \ No newline at end of file diff --git a/rest/index.html b/rest/index.html new file mode 100644 index 0000000..68efde9 --- /dev/null +++ b/rest/index.html @@ -0,0 +1,12 @@ + + + + + + Posts + + + + + + \ No newline at end of file diff --git a/rest/posts.js b/rest/posts.js new file mode 100644 index 0000000..fbddbfc --- /dev/null +++ b/rest/posts.js @@ -0,0 +1,15 @@ +let keres=new XMLHttpRequest(); +let valasz=""; + +keres.open('GET','https://jsonplaceholder.typicode.com/posts',true); + +keres.onload=function(){ + valasz=JSON.parse(this.response); + console.log(valasz); +} + +keres.send(); + +console.log("Válasz:"+valasz); + +