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 7732995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:52:19+00:00 2026-06-01T06:52:19+00:00

My ASP.NET MVC page uses JavaScript/jQuery to poll my database every second. This is

  • 0

My ASP.NET MVC page uses JavaScript/jQuery to poll my database every second.

This is working but I want to make sure that, if there is a delay, my timer handler won’t get called again before it has returned.

In there any trick to this other than storing the timer ID in a global variable, clearing the timer in my handler, and restarting it when my handler is done.

NOTE: I realize every second seems frequent but this code is polling my server after submitting a credit card payment. Normally, it will only run for a second or so, and I don’t want the user to wait any longer than necessary.

  • 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-01T06:52:20+00:00Added an answer on June 1, 2026 at 6:52 am

    Polling every second? That’s quite heavy!

    That aside, you won’t have this issue when setTimeout is used instead of setInterval. The latter ensures that a piece of code is run x times given a interval, while the former ensures that there’s a delay of at least x milliseconds.

    function some_poller() {
        $.ajax({
           url: '/some_page',
           success: function() {
               setTimeout(some_poller, 1000);
           },
           error: function() { // Also retry when the request fails
               setTimeout(some_poller, 1000);
           }
        });
    }
    
    // Init somewhere
    some_poller();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Single Application Page Asp.net MVC 4 temlplate uses default database to check Login and
We have a ASP.NET MVC 3 application that uses unobtrusive jQuery validation. The page
I am using asp.net mvc, C# and jquery. My site is uses ajax heavily.
I have an Asp.net MVC application which uses html5 and jquery on the client
I have an ASP.NET MVC application that uses LINQ2SQL as the database layer. I
I've been working on an ASP.net MVC project that uses checkbox HTML Helpers in
I'm working on an ASP.NET MVC app that uses a Flash movie as a
I'm working on a mvc application that uses jquery to implement dynamically loading page
I have asp.net mvc application, that uses razor view engine. I want to send
Context: asp.net MVC 3 app. Page1 is a mobile page using jquery mobile and

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.