Created
July 30, 2020 00:39
-
-
Save amyunus/cf541d06e5b0016d3231c0646c423ebe to your computer and use it in GitHub Desktop.
This file contains 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 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