12345678910111213141516171819202122232425 |
- <header>
- fetch basic
- </header>
- <body>
- <script>
- fetch('https://swapi.dev/api/people/1/')
- .then(res => res.json())
- .then(luke => {
- let table = document.createElement("table");
- for (let key in luke) {
- let row = document.createElement("tr");
- table.append(row);
- let nameTd = document.createElement("td");
- nameTd.innerText = key;
- row.append(nameTd);
- let valueTd = document.createElement("td");
- valueTd.innerText = luke[key];
- row.append(valueTd);
- }
- table.border = "1";
- document.body.append(table);
- });
- </script>
- </body>
|