This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

XMLHttpRequest

Summary

Represents an XML request using HTTP.

Property of dom/Windowdom/Window

Syntax

Note: This property is read-only.

var xhr = window.XMLHttpRequest;

Return Value

Returns an object of type DOM NodeDOM Node

An XMLHttpRequest instance object.

Examples

The following script demonstrates how to create and use the XMLHttpRequest object:

if (window.XMLHttpRequest)
{
  var xhr = new XMLHttpRequest();
  xhr.open("GET", "http://localhost/test.xml", true);
  xhr.onreadystatechange =
    function () {
      if (xhr.readyState === 4) {
        console.log(xhr.statusText);
     }
    };
   xhr.send();
}

Usage

 It provides an easy way to retrieve data from a URL without having to do a full page refresh. A Web page can update just a part of the page without disrupting what the user is doing.  XMLHttpRequest is used heavily in AJAX programming.

Related specifications

XMLHttpRequest
Working Draft

Attributions