diff --git a/tanuloi_nevsor/ajax.js b/tanuloi_nevsor/ajax.js new file mode 100644 index 0000000..1227b7f --- /dev/null +++ b/tanuloi_nevsor/ajax.js @@ -0,0 +1,29 @@ +let request= new XMLHttpRequest(); + +let valasz=""; + +let root=document.getElementById('root'); + +request.open('GET','https://jsonplaceholder.typicode.com/posts',true); + +request.onload=function(){ + valasz=JSON.parse(this.response); + valasz.forEach(elem=>{ + let p=document.createElement('p'); + p.textContent=elem.title; + root.appendChild(p); + }); +} + +//request.send(); + +fetch('https://jsonplaceholder.typicode.com/posts') +.then(res=>res.json()) +.then(valasz=>{ + valasz.forEach(elem=>{ + let p=document.createElement('p'); + p.textContent=elem.title; + root.appendChild(p); + }) +}).catch(err=>alert(err)); + diff --git a/tanuloi_nevsor/index.html b/tanuloi_nevsor/index.html index d95ba88..8abadbf 100644 --- a/tanuloi_nevsor/index.html +++ b/tanuloi_nevsor/index.html @@ -4,11 +4,12 @@