blog/_includes/post-counter.html

36 lines
905 B
HTML

<em id="postvisitcounter">
</em>
<!-- <script defer>
function postvisits(response) {
document.getElementById('postvisitcounter').innerText = response.value;
}
</script>
<script async src="http://localhost:5016/GetCounter/test?callback=postvisits"></script> -->
<script>
function ajax(url) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
resolve(this.responseText);
};
xhr.onerror = reject;
xhr.open('GET', url);
xhr.send();
});
}
var siteId = "{{ site.id }}";
var postId = "{{ page.title }}";
ajax("http://localhost:5016/GetCounter?siteId="+ siteId + "&postId=" + postId)
.then(function(result) {
console.log(result); // Code depending on result
document.getElementById('postvisitcounter').innerText = result;
})
.catch(function() {
// An error occurred
});
</script>