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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:22:09+00:00 2026-06-09T23:22:09+00:00

I have a strange situation. Try double clicking on Insane on this fiddle .

  • 0

I have a strange situation.

Try double clicking on “Insane” on this fiddle. You will notice that onreadystatechange is called 3 times. All these times with readyState = 4. For me, this is insane.

But the zinger is that when I remove the alert(added) from the double click event listener function as shown in this fiddle, then everything is OK.

Is there somebody who can explain to me what happened ? It is very strange for me.Thanks in advance. 🙂

  • 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-09T23:22:11+00:00Added an answer on June 9, 2026 at 11:22 pm

    This is happening because your XMLHttpRequest is set to execute asynchronously and your alert('added') halts the JavaScript execution thread before XMLHttpRequest begins to invoke onreadystatechange. By the time you close the alert, the XMLHttpRequest has already completed and the four calls to onreadystatechange are sitting in the stack, pending execution.

    Thus, because your XMLHttpRequest has already completed, .readyState and .status are already equal to 4 and 200 respectively. So with each .onreadystatechange call, your if statements evaluate true.

    If you change the XMLHttpRequest to execute synchronously (or if you place alert('added') before invoking AJAX), then you get the number of alerts you would expect:

    http://jsfiddle.net/B9a5G/6/

    More on JavaScript events, timing and single-threaded processing:

    http://javascript.info/tutorial/events-and-timing-depth

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

Sidebar

Related Questions

Strange situation. inside a solution I have several projects. One of them is called
I guess this is strange situation. I have a results table which contain 100k
I am running into a very strange situation with an app I have that
I have a very strange situation. Basically I have code that uses a decryptor
a noob question here. I have a very strange situation that's very puzzling to
I'm experiencing this strange situation. I have a UITableView where, when the user selects
I have strange situation - when I'm trying to update model, that can contains
I have a strange situation in regards to xml serialization... If I run MyApp.exe
I have a strange situation here. In my android app, I have a layout
I have a very strange situation. I have a large set of records to

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.