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 超文本应用程序技术工作组) 实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
responseXML
|
Chrome Yes | Edge 12 |
Firefox
Yes
|
IE Yes | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes |
Firefox Android
Yes
|
Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
完整支持
见实现注意事项。
XMLHttpRequest
XMLHttpRequest.response
XMLHttpRequest.responseType
DOMParser
XMLSerializer
(specifically, the
serializeToString()
method)
XMLHttpRequest