详见这里:Bug 651072 - Support HTML parsing in XMLHttpRequest per XMLHttpRequest Level 2

假想代码:

function getDocument (aURL, aCallback) {
  var xhr = new XMLHttpRequest;
  xhr.open("GET", aURL, true);
  xhr.responseType = "document";
  xhr.onreadystatechange = function() {
    if (xhr.readyState === xhr.DONE /* 4 */ &&
        xhr.status === 200) {
      aCallback(xhr.response);
    }
  };
  xhr.send(null);
}

getDocument("http://www.example.com", function (doc) {
  console.log(doc.querySelector("h1").innerHTML);
});

从这趋势来看,末来许多要用类库实现的东西,浏览器都给你内置了。

相关文章:

  • 2021-10-05
  • 2021-10-28
  • 2022-02-23
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2021-06-26
猜你喜欢
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
  • 2021-12-01
  • 2021-09-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案