xxxxxxxxxx
<!DOCTYPE html>
<html>
<title>AJAX 发送GET 请求示例 - 基础教程(div.cn)</title>
<body>
<h2>AJAX GET 请求</h2>
<button type="button" onclick="fetchDoc()">获取内容</button>
<div id="output"></div>
<script>
function fetchDoc() {
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
document.getElementById("output").innerHTML = this.responseText;
}
};
httpRequest.open("GET", "ajax_get.php?fname=Seagull&lname=Anna", true);
httpRequest.send();
}
</script>
</body>
</html>