4. Properties of XMLHttpRequest Object

Properties of XMLHttpRequest Object
Coming to the properties, there are totally 8 properties, here we are discussing
only 3 properties in detail which are almost enough and important. To see all the list of 8 properties click here.


1. readyState : This property will retrieve the current state of the request
operation
Syntax : [nState=] object.readyState
Here nState will be returned with the following values(0,1,2,3,4) only
0 (Uninitialized) The object has been created, but not initialized (the open
method has not been called).
1 (Open) The object has been created, but the send method has not been called.
2 (Sent) The send method has been called. responseText is not available. responseBody
is not available.

3 (Receiving) Some data has been received. responseText is not available.
responseBody is not available.

4 (Loaded) All the data has been received. responseText is available.
responseBody is available.


Based on the return value, the state of the request is known
2. responseText : Retrieves the response body as astring (from the server)
3. responseXML: Retrieves the response body as an XML Document Object Model
(DOM) object.


Example:
For page loading the status bar shows the loading of the page, but an ajax page
loading is not known so, we have to create our own labels to tell the user about
the process that is taking place.
For example, while registering in any website, if we give user name then the
request is gone to the server for the availability checking at that time we can
see PleaseWait or Checking Labels are displayed. This can be done using these
properties.
First we know the state by using the ready state and then appropriate message is
displayed using the 2,3 properties.


Points To Remember:

1. readyState : This property will retrieve the current state of the request
operation
2. responseText : Retrieves the response body as astring (from the server)
3. responseXML: Retrieves the response body as an XML Document Object Model
(DOM) object.




Go to Lesson 5
or
See The Extended properties Of XMLHttpRequest Object