13 尚硅谷 AJAX AJAX POST设置请求体
修改index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ajax post 请求</title>
<style>
#result {
width: 200px;
height: 100px;
border: solid 1px;
}
</style>
</head>
<body>
<div id="result"></div>
</body>
<script>
const result=document.getElementById("result")
result.addEventListener("mouseover",function(){
const xhr=new XMLHttpRequest();
xhr.open("POST","http://192.168.1.254:8000/server")
xhr.send('1324134123412432')
xhr.onreadystatechange=function(){
if(xhr.readyState===4){
if(xhr.status>=200 && xhr.status<300){
result.innerHTML=xhr.response
}
}
}
})
</script>
</html>