<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CORS</title>
<style>
#result{
width:200px;
height:100px;
border:solid 1px #90b;
}
</style>
</head>
<body>
<button>发送请求</button>
<div id="result"></div>
<script>
const btn = document.querySelector('button');
const result = document.getElementById("result");
btn.onclick = function(){
//1. 创建对象
const x = new XMLHttpRequest();
//2. 初始化设置
x.open("POST", "http://localhost:8080/audit/audit/doMainTotalV3");
//3、设置 Content-Type属性(固定写法)
x.setRequestHeader('Content-Type', 'application/json;charset=UTF-8')
// x.setRequestHeader('Access-Token', '123123123')
//3. 发送
x.send('{"plant": "Lydia", "type": "", "token": "f5647f7ea2bd549c7afe444759fada25b3a6a67dea117cbc00e3923cf465a238", "userIdForDefaultPage": "uf103065", "plantForDefaultPage": "Lydia", "deviceType": "APP", "bottomNavigation": "ProductAudit"}');
//4. 绑定事件
x.onreadystatechange = function(){
if(x.readyState === 4){
if(x.status >= 200 && x.status < 300){
//输出响应体
console.log(x.response);
result.innerHTML=x.response;
}
}
}
}
</script>
</body>
</html>
html请求测试页面
最新推荐文章于 2024-08-22 08:30:55 发布