XMLHttpRequest.responseXML 只读特性返回 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.

注意: 名称 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: URL .

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.

句法

var data = XMLHttpRequest.responseXML;
					

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

异常

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

范例

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();
					

规范

规范 状态 注释
XMLHttpRequest
The definition of 'responseXML' in that specification.
实时标准 WHATWG (Web 超文本应用程序技术工作组) 实时标准

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
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 Yes Edge 12 Firefox Yes
Yes
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 Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android Yes
Yes
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 Yes Safari iOS Yes Samsung Internet Android Yes

图例

完整支持

完整支持

见实现注意事项。

另请参阅

元数据

  • 最后修改: