代码示例:(标识:js_ajax_xmlhttp)
<!DOCTYPE html>
<html>
<body>

<h1>XMLHttpRequest 对象</h1>

<div id="demo">
<p>让 AJAX 更改此文本。</p>
<button type="button" onclick="loadDoc()">更改内容</button>
</div>

<script>
function loadDoc() {
  const xhttp = new XMLHttpRequest();
  xhttp.onload = function() {
    document.getElementById("demo").innerHTML = this.responseText;
  }
  xhttp.open("GET", "/static/demo/txt/ajax_info.txt");
  xhttp.send();
}
</script>

</body>
</html>
运行结果: