hw_16_01_fetch_basic.html 813 B

12345678910111213141516171819202122232425
  1. <header>
  2. fetch basic
  3. </header>
  4. <body>
  5. <script>
  6. fetch('https://swapi.dev/api/people/1/')
  7. .then(res => res.json())
  8. .then(luke => {
  9. let table = document.createElement("table");
  10. for (let key in luke) {
  11. let row = document.createElement("tr");
  12. table.append(row);
  13. let nameTd = document.createElement("td");
  14. nameTd.innerText = key;
  15. row.append(nameTd);
  16. let valueTd = document.createElement("td");
  17. valueTd.innerText = luke[key];
  18. row.append(valueTd);
  19. }
  20. table.border = "1";
  21. document.body.append(table);
  22. });
  23. </script>
  24. </body>