Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7962075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:13:50+00:00 2026-06-04T05:13:50+00:00

Not sure if I’m phrasing my question right, but I have the code below.

  • 0

Not sure if I’m phrasing my question right, but I have the code below. Basically want to make an ajax request, check the call back, and re-perform the ajax until it gets the desired response (in the example connectedvoter==1).

The problem is it only takes like 80ms and the amount of xhr’s gets to huge numbers really fast at that speed. I tried to come up with a way to ‘pause’ but everything I could think of ate up cpu.

Is there a way to ‘slow down’ the amount of requests made, to say once a second or two without eating up cpu?

var connctedvoter = 0;
var govoters = function () {
        $.ajaxSetup({
            async: false
        });
        var url = "getconnectedvoter.php";
        var data = {
            userid: userid
        };
        $.getJSON(url, data, callback);
    };
var pausevoters = function () {
        console.log("pausing ajax voters");
    };
var callback = function (response) {
        if (response.error) {
            return;
        }
        if (response.connectedvoter == 0) {
            setTimeout(govoters, 150);
            //govoters();
        } else {
            $('#vanid').html(response.vanid);
            $('#name').html(response.name);
            $("#mapurl").attr("src", response.mapurl);
            $('.call').fadeIn();
            return;
        }
    };
//DO THIS TO START
setTimeout(govoters, 150);
pausevoters();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:13:52+00:00Added an answer on June 4, 2026 at 5:13 am

    Just increase the delay of the timeout:

    if(!response.connectedvoter) {
      setTimeout(govoters, 2000); // instead of 150
    }
    

    Instead of 10 requests for a second:

    setTimeout(govoters, 150); // one request every 150 millisecond. 
    

    Note that for start you can change from this:

    //DO THIS TO START
    setTimeout(govoters, 150);
    

    To this:

    //DO THIS TO START
    govoters();
    

    There isn’t really a need for a timeout here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not sure if that the right title for the question, but what I'm trying
Not sure if this is the right place for MDX question but it seemed
Not sure if this is the right stack to be asking this question, but
Not sure if the title is quite right for the question but I can't
Not sure if I worded this correctly ... but I have the following code:
Not sure how to word the question... Basically, so far all my SQL stuff
not sure what is wrong with this jquery code: http://jsfiddle.net/aCABM/ I want to to
Not sure if this is too open-ended of a question for StackOverflow but, I'm
not sure what i'm missing, but here ti go's: i have a floating left
Not sure what I'm doing wrong, but here is the code 1: var currDoc:NotesDocument

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.