XMLHttpRequest

from Wikipedia, the free encyclopedia

XMLHttpRequest (short: XHR ) is a programming interface for JavaScript for transferring data via HTTP . Contrary to the name, this data does not have to be XML. XMLHttpRequest forms a basic component of the Ajax technology.

XMLHttpRequest enables a website script to dynamically retrieve data from the web server without having to reload the HTML page. Previously, this was only possible through the use of invisible HTML frames or IFrames or with dynamically loaded script files. Since data can be processed asynchronously with the XMLHttpRequest procedure , a script does not have to wait until the request has been answered, but can instead concentrate on other tasks.

The interface description of the XMLHTTPRequest object according to the standardization proposal of the W3C .

All HTTP request methods (including GET, POST, HEAD, PUT) can be used with XMLHttpRequest . If a request delivers XML data, XMLHttpRequest can send it back either as text or as a DOM tree structure. The latter is suitable, for example, for communicating with web services .

history

The XMLHttpRequest technology was originally developed by Microsoft and is available in Internet Explorer from version 5.0 as an ActiveX object. Many browsers support this API, next to the Internet Explorer (version 7 as XMLHttpRequest ) is the Mozilla and all other Gecko - derivatives (version 1.0), Opera (version 7.6 Beta) and Apple Safari (version 1.2), Konqueror and all other KHTML derivatives.

As can be seen from the individual interface descriptions of the various XMLHttpRequest implementations, these are not completely compatible with one another. For this reason, a uniform definition for the XMLHttpRequest object was proposed by the W3C for standardization in December 2012 .

Code samples (JavaScript)

The following example calls a resource on the same domain via XMLHttpRequest and outputs the content in a message window. If the call to the resource fails, no message is issued:

var xmlHttp = null;
try {
    xmlHttp = new XMLHttpRequest();
} catch(e) {
    // Fehlerbehandlung, wenn die Schnittstelle vom Browser nicht unterstützt wird.
}
if (xmlHttp) {
    xmlHttp.open('GET', 'beispiel.xml', true);
    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4) {
            alert(xmlHttp.responseText);
        }
    };
    xmlHttp.send(null);
}

XMLHttpRequest Level 2

An extended specification of XMLHttpRequest has had the status of a working draft at the W3C since January 2012 . Cross- domain queries, support of data streams , etc. are planned.

Individual evidence

  1. Ajax Patterns - On-Demand Javascript ( Memento of the original from April 22, 2011 in the Internet Archive ) Info: The archive link was inserted automatically and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice.  @1@ 2Template: Webachiv / IABot / ajaxpatterns.org
  2. Interface description of the XMLHttpRequest object for the IE
  3. Interface description of the XMLHttpRequest object for Mozilla
  4. Interface description of the XMLHttpRequest object for Safari
  5. Interface description of the XMLHttpRequest object proposed by the W3C
  6. XMLHttpRequest Level 2, W3C