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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:00:25+00:00 2026-05-25T12:00:25+00:00

Here’s a sample XMLHttpRequest I cobbled together from w3schools <html> <head> <script type=text/javascript> function

  • 0

Here’s a sample XMLHttpRequest I cobbled together from w3schools

<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
  var T="nothing";

  xmlhttp=new XMLHttpRequest();
  xmlhttp.overrideMimeType('text/plain');  // don't sc
  xmlhttp.onreadystatechange=function()
  {
    alert ("rdystate: " + xmlhttp.readyState);
    alert ("status: "   + xmlhttp.status);
    alert ("Text: "     + xmlhttp.statusText);
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
      T = xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","SBL_PROBES.htm",true);
xmlhttp.send(null);
//T = xmlhttp.responseText;
alert(T);
}
</script>
</head>
<body>

<h2>Using the XMLHttpRequest object</h2>
<div id="myDiv"></div>
<button type="button" onclick="loadXMLDoc()">CHange Content</button>

</body>
</html>

XMLHttpRequest always returns a zero status.

Nothing shows up in Firefox’s error console.

If I change the request to synchronous one by changing the line

xmlhttp.open("GET","SBL_PROBES.htm",true);

to

xmlhttp.open("GET","SBL_PROBES.htm",false);

and un-comment the line

//T = xmlhttp.responseText;

The text of the requested file is returned.

The HTM and the file reside in the same directory. If you try this you will need a file SBL_PROBES.htm there also, it’s contents are irrelevant.

I’m using Firefox 3.6.22.

Could this be a cross domain problem? If so, why does it work as a synchronous request?

  • 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-25T12:00:26+00:00Added an answer on May 25, 2026 at 12:00 pm

    You can use a function inside the if statement. This function is executed when readystate changes to 4.

    var handleResponse = function (status, response) {
       alert(response)
    }
    var handleStateChange = function () {
       switch (xmlhttp.readyState) {
          case 0 : // UNINITIALIZED
          case 1 : // LOADING
          case 2 : // LOADED
          case 3 : // INTERACTIVE
          break;
          case 4 : // COMPLETED
          handleResponse(xmlhttp.status, xmlhttp.responseText);
          break;
          default: alert("error");
       }
    }
    var xmlhttp=new XMLHttpRequest();
    xmlhttp.onreadystatechange=handleStateChange;
    xmlhttp.open("GET","SBL_PROBES.htm",true);
    xmlhttp.send(null);
    

    Your old code did a asynchronous call and continued just with the alert Statement. T was empty at this time.

    Ok, I’ll explain a little bit how this whole thing works:

    First we define two callback functions, which we call later in the request, named handleResponse and handleStateChange.

    Afterwards we create a Object, which represents the XMLHttpRequest

    var xmlhttp=new XMLHttpRequest();
    

    This results in an Object as follows (simplyfied):

    XMLHttpRequest { status=0, readyState=0, multipart=false, onreadystatechange=handleEvent()}
    

    With the open(…) function call you set parameters for the request:

    xmlhttp.open("GET","SBL_PROBES.htm",true);
    

    This means, do a asynchronous GET Request to fetch the Page SBL_PROBES.htm
    Then the send(…) function is called which fires the request itself.

    We registered a callback function for the onreadystatechange, as you can imagine, this is actually an eventHandler. Each time the state changes this function is called. (It is the same as if you register a callback function to an onKeyUp Event in a form, this callback is triggered each time your key goes up 🙂 )

    The only case which is of interest for your problem is state 4. Therefor the handleRequest callback function is called only in state 4. At this time you Request has actually a result, and further a status. (Status means your webserver returned a status code 200=ok, 404=not found etc.)

    That is not all the magic which is behind the ajax stuff, but should give you a simplified overview, what is actually happening behind the scenes.
    It is important that you test this on a webserver, do not use file:// for testing.

    If you need more in detail info, just let me know.

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

Sidebar

Related Questions

Here's an excerpt from java.text.CharacterIterator documentation: This interface defines a protocol for bidirectional iteration
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Here is an example table: ID time data type 0 0100 xyz 0 1
Here is a snippet of my form <form action= method=post onsubmit=return verify()> <input type=submit
Here, i have coded to get data from DB. I want to store the
Here is a shell script: echo Starting Jarvis Program D. ALICE_HOME=. SERVLET_LIB=lib/servlet.jar ALICE_LIB=lib/aliceserver.jar JS_LIB=lib/js.jar
Here's my button element: <button type=submit class=btn-submit><span><strong>Let Me In, please!</strong></span></button> and here's the CSS:
here is how i call the following function: List<decimal> numbers = new List<decimal>(); numbers.Add(210m);
Here is my text file forms. S1,F2 title including several white spaces (abbr) single,Here<->There,reply
Here's my test function (c#, visual studio 2010): [TestMethod()] public void TestGetRelevantWeeks() { List<sbyte>

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.