Unsere Freiwilligen haben diesen Artikel noch nicht in Deutsch übersetzt. Machen Sie mit und helfen Sie, das zu erledigen!
Sie können den Artikel auch auf English (US) lesen.

The XMLHttpRequest.responseXML property is a read-only value which returns a Document containing the HTML or XML retrieved by the request, or null if the request was unsuccessful, has not yet been sent, or if the retrieved data can't be correctly parsed as XML or HTML. The response is parsed as if it were a "text/xml" stream. When the responseType is set to "document" and the request has been made asynchronously, the response is parsed as a "text/html" stream. responseXML is null for any other types of data, as well as for data: URLs.

Note: The name responseXML is an artifact of this property's history; it actually works for both HTML and XML.

If the server doesn't specify the Content-Type header as "text/xml" or "application/xml", you can use XMLHttpRequest.overrideMimeType() to force XMLHttpRequest to parse it as XML anyway.

Syntax

var data = XMLHttpRequest.responseXML;

Value

A Document containing the nodes resulting from parsing XML or HTML received using XMLHttpRequest, or null if no data has been received or the data is not of the correct type.

Exceptions

InvalidStateError
The responseType isn't either "document" or an empty string (either of which indicates that the received data is XML or HTML).

Example

var xhr = new XMLHttpRequest();
xhr.open('GET', '/server', true);

// If specified, responseType must be empty string or "document"
xhr.responseType = 'document';

// overrideMimeType() can be used to force the response to be parsed as XML
xhr.overrideMimeType('text/xml');

xhr.onload = function () {
  if (xhr.readyState === xhr.DONE) {
    if (xhr.status === 200) {
      console.log(xhr.response);
      console.log(xhr.responseXML);
    }
  }
};

xhr.send(null);

Specifications

Specification Status Comment
XMLHttpRequest
The definition of 'responseXML' in that specification.
Living Standard WHATWG living standard

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support Yes12 Yes1 Yes Yes Yes
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support Yes Yes Yes Yes1 Yes Yes Yes

1. Prior to Firefox 51, an error parsing the received data added a <parsererror> node to the top of the Document and then returned the Document in whatever state it happens to be in. This was inconsistent with the specification. Starting with Firefox 51, this scenario now correctly returns null as per the spec.

See also

Schlagwörter des Dokuments und Mitwirkende

Mitwirkende an dieser Seite: Sheppy, ExE-Boss, erikadoyle, MashKao, jsx
Zuletzt aktualisiert von: Sheppy,