Skip to content

Instantly share code, notes, and snippets.

@gilapo
Created July 12, 2021 17:29
Show Gist options
  • Save gilapo/5f4c2994029806a1a44c2732e493027a to your computer and use it in GitHub Desktop.
Save gilapo/5f4c2994029806a1a44c2732e493027a to your computer and use it in GitHub Desktop.
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