Ajax request makes the count continuously increasing
See original GitHub issueHello,
I don’t know if i’m miss-using your plugin or if it’s me but given this code:
/**
* Replace target element inner html
* @param {*} elementId
* @param {*} text
*/
function replaceTextInElementById(elementId, text){
document.getElementById(elementId).innerHTML = text;
};
/**
* Make ajax request and update hits counter
* @param {*} url
* @param {*} elementId
*/
function updateHitCounterText(url, elementId) {
return $.ajax('https://hitcounter.pythonanywhere.com/count',{data:{url: url}}).then(hitCount => {
replaceTextInElementById(elementId, hitCount);
});
};
const baseUrl = window.origin + '{{ site.baseurl }}'; // i.e: http://localhost:4000/blog
updateHitCounterText(baseUrl, 'total-hits-counter');
The counter is increasing continuously, making it kinda inaccurate. Tbh, that’s not much a problem, but since the image is working as intended (not increasing even if you spam refresh), I was wondering if this was normal 😉
Thanks for reading, and thanks for your simple yet very nice work!
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Continuous AJAX requests increasing resource count and size
I need to perform semi-continuous AJAX requests to display data based on the latest entry into a DB. This all works fine with...
Read more >JavaScript console.count() Method - W3Schools
Call console.count() 5 times, with a label: for (let i = 0; i < 5; i++) { ... The count() method counts the...
Read more >10 Most Common Mistakes That PHP Developers Make - Toptal
Assume we make a server request with a jQuery.ajax() call as follows: ... It's also worth noting that, in PHP, count() is constant...
Read more >Getting started - Developer guides - MDN Web Docs
The optional third parameter sets whether the request is asynchronous. If true (the default), JavaScript execution will continue and the user ...
Read more >AJAX Collection in Application Insights - Microsoft Azure
If your page makes AJAX calls synchronously while it's loading, slow responses can be a cause of slow page loads. On the Browsers...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looks like it’s working - I also updated the REAMDE 👍
Ah yes, the origin! Putting the origin in
Access-Control-Allow-Origin
should work and defaulting it to'*'
if no origin is available. I’ll look into this now, thank you.