Created
July 12, 2021 17:29
-
-
Save gilapo/5f4c2994029806a1a44c2732e493027a to your computer and use it in GitHub Desktop.
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
function loadContent() { | |
var url = "https://jsonplaceholder.typicode.com/posts/"; | |
fetch(url) | |
.then((response) => response.json()) | |
.then(function (data) { | |
var template = data.map((post) => { | |
return ` | |
<h3>${post.title}</h3> | |
<p>${post.body}</p> | |
<hr> | |
`; | |
}); | |
document.getElementById("hasil").innerHTML = template.join("<br>"); | |
}) | |
.catch(function (e) { | |
alert("gagal mengambil data"); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment