xxxxxxxxxx
<!DOCTYPE html>
<html>
<title>AJAX 发送POST 请求示例 - 基础教程(div.cn)</title>
<body>
<h2>AJAX POST 请求</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("POST", "ajax_post.php", true);
httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
httpRequest.send("fname=Seagull&lname=Anna");
}
</script>
</body>
</html>