Created
August 23, 2026 10:37
-
-
Save kpliuniverse/6e79f8e98cbb4efaefb3e9b3ffd80d7e to your computer and use it in GitHub Desktop.
Event-driven programming async
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <title>Document</title> | |
| </head> | |
| <body> | |
| <h2>Posts</h2> | |
| <h3 id="loading">Loading posts...</h3> | |
| <h3 id="posts"></h3> | |
| <script> | |
| const loading = document.getElementById("loading"); | |
| const posts = document.getElementById("posts"); | |
| const getData = fetch("https://jsonplaceholder.typicode.com/posts"); | |
| getData | |
| .then((response) => response.json()) | |
| .then((data) => { | |
| loading.style.display = "none"; | |
| data.slice(0, 10).forEach((post) => { | |
| posts.innerHTML += ` | |
| <div> | |
| <h2>${post.title}</h2> | |
| <p>${post.body}</p> | |
| </div> | |
| `; | |
| }); | |
| }) | |
| .catch((error) => { | |
| loading.textContent = "Failed to load posts."; | |
| console.log("Error: ", error); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment