XMLHttpRequest Properties

Here is list of XMLHttpRequest object properties.

onreadystatechange An event handler for an event that fires whenever the readyState property changes.

readyStateThe readyState property keeps track the current state of the XMLHttpRequest object.It returns an integer.

  • 0: uninitialized request
  • 1: connection established
  • 2: sent request
  • 3: processing request
  • 4: request complete

responseText responseText returns the respone data as a string.

status status returns a number 200: "OK" and 404: Page not found.

Example

function loadMyFile()
{
var xmlhttpobject;
if (window.XMLHttpRequest)
  {
 // code for new browser
  xmlhttpobject=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttpobject=new ActiveXObject("Microsoft.XMLHTTP");
  }

 xmlhttpobject.onreadystatechange=function()
  {
  if (xmlhttpobject.readyState==4 && xmlhttpobject.status==200) 
    {
    document.getElementById("myDiv").innerHTML=xmlhttpobject.responseText;
    }
  }
}

When readyState is equal to 4 and status is equal to 200 mean response is ready.