怎样获取从服务器返回的xml或html文档对象?

使用 xhr.responseXML;

通过这个属性正常获取XML或HTML文档对象有两个前置条件:

1. Content-Type头信息的值等于: text/xml 或 application/xml

2. xhr.responseType 需要赋值为: "document"

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

xhr.responseType = 'document';
xhr.overrideMimeType('text/xml');

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

xhr.send(null);

注意: 如果Content-Type不等于 text/xml 或 application/xml, 那需要通过xhr.overrideMimeType('text/xml') 强制进行XML解析.