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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:48:14+00:00 2026-05-17T22:48:14+00:00

I have a race condition in which I do not want an AJAX call

  • 0

I have a race condition in which I do not want an AJAX call to occur, if a form on the page is currently submitting.

I’d rather not alter the code for the form.

I was thinking of attaching event handlers to each of the form elements so that onsubmit it would increment a counter and then on onreadystatechange decrement the counter.

Then before the AJAX call, check to ensure the counter is zero before firing.

However is there an easier way such as (pseudo code):

form.isSubmitting 

EDIT:

The race condition is not because of the JavaScript per-say. It is caused by what happens on the server side on response of the ordering of these actions.

To give you an idea of the broader problem:

A cookie is set when the form post returns.
On the AJAX call (needs to happen every X seconds)… the server-side (if the form post has happened) expects the cookie to be set.

Sometimes….

If there is a delay in the form submission returning (and setting the cookie client side), the AJAX call is triggered without sending the cookie back.

The server expects the cookie, because as far as it is concerned the form post has been successful.

However it is the client side I need to control to ensure the actions are performed in a prescribed way.

So correct JavaScript itself cannot cause race conditions, but (as far as my testing has shown) – the submission and returning of POST/AJAX calls causes a race condition in my particular case.

  • 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-05-17T22:48:15+00:00Added an answer on May 17, 2026 at 10:48 pm

    There are no “race conditions” in Javascript on a web page, because there’s just one thread of execution. If you want to prevent event handlers from doing anything after a form has been submitted (or at any time, really), the very simplest thing to do is set some globally-accessible flag. The handler routines just have to check for that. Of course it’s important that the flag is cleared when appropriate.

    edit — OK after your edit, it’s a little more clear what you’re doing, but one thing is not clear: how exactly is the form being posted? Is it a “natural” form post? If that’s the case, the whole page is going to be reloaded by the response. Is the target a separate <iframe> perhaps?

    Or is the form being submitted by some other AJAX code?

    1. If the form is being submitted “naturally” by the browser, and we’re talking about a whole page being reloaded, then that’s probably the simplest case. The form’s “submit” handler should simply set the global flag, and the code running via the interval timer should just do nothing on the intervals when the flag is set. There’s no need to worry about clearing the flag, because the page is going to blasted by the response anyway.

    2. If the form is posting within an <iframe> on the page, or posting to a hidden <iframe>, then it’s almost the same as (1) except that the response page will need to clear the global flag. Exactly how to do that depends on what the application setup involves, but basically it’ll just be some Javascript in the response that sets top.postingFlag to false (or whatever).

    3. If it’s separate AJAX code that’s posting the form, then you’d set the flag when you start the XMLHttpRequest, and clear it in the handler(s) for success/failure.

    In all cases, the key is for code in the interval timer to watch for the state of the flag, and avoid posting when the flag is set.

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

Sidebar

Related Questions

I have something wich looks to me like race condition while logging to file
I have a question regarding a race condition scenario. The question: Consider the following
I have an issue that looks like a race condition with a webview callback
According to an article on IBM.com, a race condition is a situation in which
This post is related to: POSIX TIMER- Have multiple timers I want to call
We have a process updating the database which uses the following SQL IF NOT
I have an older validation form which is depends on the prototype.js library. Unfortunately
We have created a lock file to avoid a race condition. The lockfile is
I have a question about race conditions and simultaneous writes. I have a class
Is there a tool that analyses .NET code and finds race conditions? I have

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.