<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="button" value="发送ajax异步请求服务器" onclick="butOnclick()">
<div id="myDiv"></div>
<script>
function butOnclick() {
const xmlhttp = new XMLHttpRequest()
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
document.getElementById('myDiv').innerHTML = xmlhttp.responseText
}
}
xmlhttp.open('GET', 'http://localhost:8080/jsajaxproject/js_ajax', true)
xmlhttp.send()
}
</script>
</body>
</html>
01-13
3967
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-09
1148
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-05
1320
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)