Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. const final = document.getElementById('demo');
  2.  
  3. const container = document.createElement('div');
  4. container.setAttribute('class', 'container');
  5.  
  6. final.appendChild(container)
  7.  
  8. var request = new XMLHttpRequest();
  9. request.open('GET', 'https://jsonplaceholder.typicode.com/posts?fbclid=IwAR2aHkMfSVPYV3va38MKu-jOahl9G8UzyPJ1Dd67EyskMPZMw1gN9xi-AUg', true)
  10. request.onload = function() {
  11. var data = JSON.parse(this.response)
  12.  
  13. if (request.status >= 200 && request.status < 400) {
  14. data.forEach(user => {
  15.  
  16. const card = document.createElement('div')
  17. card.setAttribute('class', 'card')
  18.  
  19. const h3 = document.createElement('h3');
  20. h3.textContent = `ID: ` + user.id;
  21.  
  22. const h4 = document.createElement('h4');
  23. h4.textContent = `Title: ` + user.title;
  24.  
  25. const p = document.createElement('p');
  26. p.textContent = `Description: ` + user.body;
  27.  
  28. container.appendChild(card);
  29. card.appendChild(h3)
  30. card.appendChild(h4)
  31. card.appendChild(p)
  32. })
  33. } else {
  34. console.log('error')
  35. }
  36. }
  37.  
  38. request.send();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement