question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ajax request makes the count continuously increasing

See original GitHub issue

Hello,

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:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
brentvollebregtcommented, Dec 4, 2020

Looks like it’s working - I also updated the REAMDE 👍

0reactions
brentvollebregtcommented, Dec 4, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found