学习中心 /编程 /XML /实战应用 /XMLHttpRequest 读取 XML
🏷️ XML 实战应用 💾 下载配套软件

XMLHttpRequest 读取 XML

异步加载并解析 XML 文件。

📅 2026-11-23 👁 16 次阅读

本节要解决的问题

异步加载并解析 XML 文件。

核心要点

  • 创建 XMLHttpRequest 对象
  • onreadystatechange 处理结果
  • responseXML 得到文档对象
var xhttp = new XMLHttpRequest();\nxhttp.onreadystatechange = function () {\n  if (this.readyState == 4 && this.status == 200) console.log(this.responseXML);\n};\nxhttp.open("GET", "note.xml", true);\nxhttp.send();
现在更常用 fetch + DOMParser,思路是一样的。