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

I have some C# code which formats a MS Project file. This code works
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
This should be a very simple thing to have run, but for some reason
I have an application that runs in the background only (by specifying LSBackgroundOnly in
I have an html file that accepts user inputs then uses Javascript to calculate
I get this error whenever i run the program Assignment makes pointer from Integer
I am getting this error whenever I try to run GCC outside of its
Whenever I run vm.runInThisContext(code, filename) , the code I ran reports __filename and __dirname
Whenever I run any jython program in Eclipse, I got the following error in

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.