32 lines
1.0 KiB
HTML
32 lines
1.0 KiB
HTML
<i class="fa fa-eye fa-fw me-1" {% if include.tooltip %} title="{{site.data.locales[include.lang].post.views}}"
|
|
data-bs-toggle="tooltip" data-bs-placement="bottom" {% endif %}></i>
|
|
<em id="visit-count">
|
|
</em>
|
|
|
|
<script>
|
|
document.getElementById("postvisitcounter").style.visibility = "hidden";
|
|
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("{{site.custom-config.blog-services.service_url}}/GetPostViews?siteId=" + siteId + "&postId=" + postId)
|
|
.then(function (result) {
|
|
console.log(result); // Code depending on result
|
|
document.getElementById('visit-count').innerText = result;
|
|
document.getElementById("postvisitcounter").style.visibility = "visible";
|
|
})
|
|
.catch(function () {
|
|
// An error occurred
|
|
});
|
|
</script> |