Web/API/XMLHTTPRequest/responseXML

From Get docs


The XMLHttpRequest.responseXML read-only property 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 data can't be parsed as XML or HTML.

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


Usually, the response is parsed as "text/xml". If the responseType is set to "document" and the request was made asynchronously, instead the response is parsed as "text/html". responseXML is null for any other types of data, as well as for data: URLs.

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

This property isn't available to workers.

Syntax

var data = XMLHttpRequest.responseXML;

Value

A Document from parsing the XML or HTML received using XMLHttpRequest, or null if no data was received or if the data is not XML/HTML.

Exceptions

InvalidStateError
The responseType isn't either "document" or an empty string.

Example

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

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

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

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

xhr.send();

Specifications

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

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
responseXML Chrome

Full support Yes

Edge

Full support 12

Firefox Full support Yes

Notes'

Full support Yes

Notes'

Notes' 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.

IE

Full support Yes

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android Full support Yes

Notes'

Full support Yes

Notes'

Notes' 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.

Opera Android

Full support Yes

Safari iOS

Full support Yes

Samsung Internet Android

Full support Yes

Legend

Full support  
Full support
See implementation notes.'
See implementation notes.


See also