views:

133

answers:

2

In the XMLHttpRequest Spec it says that:

The DONE state has an associated error flag that indicates some type of network error or abortion. It can be either true or false and has an initial value of false.

Also says something similar about a "send() flag" in an "OPENED" state.

It's said in the specification but not in the IDL and when I create a new XMLHttpRequest I can't find those "flags".

Where are those boolean variables?

+5  A: 

The XMLHttpRequest.readyState property is what you're looking for.

From the Spec you've given, you will see that all those "boolean" flags are actually numeric values.

  • UNSENT (numeric 0)
  • OPENED (numeric 1)
  • HEADERS_RECEIVED (numeric 2)
  • LOADING (numeric 3)
  • DONE (numeric 4)

These values are the result of XMLHttpRequest.onreadystatechange event handler. Basically, in order to get those values, do something of this effect.

//In Javascript
var request = new XMLHttpRequest();
if (request) {
  request.onreadystatechange = function() { 
    if (request.readyState == 4) { //Numeric 4 means DONE

        }
   };

request.open("GET", URL + variables, true); //(true means asynchronous call, false otherwise)
request.send(""); //The function that executes sends your request to server using the XMLHttpRequest.
}

Bear in mind, always write the onreadystatechange event BEFORE calling the XMLHttpRequest.send() method (if you decide to do asynchronous calls). Also, asynchronous calls will call XMLHttpRequest.onreadystatechange event listener so it's always vital you have that implemented.

More info on Wikipedia

The Elite Gentleman
+1 for mentioning that you have to define onreadystatechange before calling send. Common pitfall.
ItzWarty
Thanks for the information, it's neat and clear.I knew this, what I was wondering is if you have access to those "flags" directly in the object, what I wanted to know was more for sureness than for applicability (it's kind of useless, I know). Sorry if I wasn't clear in the question.I also wrote to the w3c webapps e-mail list, I'll put that on a new answer.
Tiangolo
A: 

I wrote to the webapps e-mail list about those flags, this is what they responded:

Everything that authors can use is expressed in the Web IDL fragment. Everything outside of that represents some kind of data implementations need to keep around one way or another to properly implement the specification.

(That was my doubt)

Tiangolo
Sorry to burst your bubble, but this wasn't the place to comment on your own question.
The Elite Gentleman