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

  • Home
  • SEARCH
  • 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 551217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:22:12+00:00 2026-05-13T11:22:12+00:00

Whenever I run this file the code runs up to the point where the

  • 0

Whenever I run this file the code runs up to the point where the send function fires and then it only fires if I have an alert function directly behind it, if I take out the alert(“sent”); out then it replies with ServerReadyyState is:1.

What could possibly be the problem? Someone please help, I’ve tried it on my local machine and on my personal server and got the same results. Any help is greatly appreciated.

The Code:

/**
 * @author d
 */
var xhr;

function getPlants(xhr) {
  try {
    xhr = new XMLHttpRequest();
  } catch (microsoft) {
    try {
      xhr = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (othermicrosoft) {
      try {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (failed) {
        xhr = false;
        alert("ajax not supported");
      }
    }
  }
  xhr.open("GET", "db_interactions.php", true);


  xhr.send(null);
  alert("sent"); //the send function only works if this alert functions is here
  if (xhr.readyState == 4) {

    return xhr.responseText;
  } else {
    alert("Server ReadyState is:" + xhr.readyState);
    xhr.abort();
    //getPlants(xhr);       
  }
}
  • 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-13T11:22:13+00:00Added an answer on May 13, 2026 at 11:22 am

    AJAX is asynchronus. You can’t just check the ready state immediately after.

    The correct design pattern is to assign a function for the AJAX call to run when the ready state changes.

    xhr.onreadystatechange = function () { alert('It changed!') }
    

    In that function, you’ll want to check if the state is 4. If so, you’re ready to process the output. If not, do nothing, since that function will be called a few times before the ready state is 4.

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

Sidebar

Related Questions

Why whenever I compile and run the following code in Visual Studio 2008: double
I have been trying to debug my code whenever I had free-time for the
Whenever I run any jython program in Eclipse, I got the following error in
I had developed an application in visual Studio 2005. whenever i run that application
whenever I try to run something in Java, Eclipse changes into the PHP perspective.
Is there a way to run some custom Javascript whenever a client-side ASP.NET validator
Whenever I'm at a break point in a certain C#.NET application in Visual Studio
I've created a one-line batch file to run SqlMetal to regenerate a LINQ to
Whenever I design a database, I always wonder if there is a best way
Whenever I try to add a new project to my SourceSafe repository it creates

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.