Skip to content

Instantly share code, notes, and snippets.

@amyunus
Created July 30, 2020 00:39
Show Gist options
  • Save amyunus/cf541d06e5b0016d3231c0646c423ebe to your computer and use it in GitHub Desktop.
Save amyunus/cf541d06e5b0016d3231c0646c423ebe to your computer and use it in GitHub Desktop.
function getArticleById() {
return new Promise(function(resolve, reject) {
// Ambil nilai query parameter (?id=)
var urlParams = new URLSearchParams(window.location.search);
var idParam = urlParams.get("id");
if ('caches' in window) {
caches.match(base_url + "article/"+idParam).then(function(response) {
if (response) {
response.json().then(function (data) {
...
...
...
document.getElementById("articles").innerHTML = articlesHTML;
resolve(data);
})
}
})
}
fetch(base_url + "article/" + idParam)
.then(status)
.then(json)
.then(function(data) {
...
...
...
document.getElementById("body-content").innerHTML = articleHTML;
resolve(data);
})
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment