var xhr = new XMLHttpRequest();
xhr.open('POST','http://127.0.0.1:3000/server');
/*
* 设置请求头
* 参数1:请求头(可自定义)
* 参数2:请求头信息
*/
xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
// xhr.setRequestHeader("name","pp");
//发送数据可以是任意类型数据
//xhr.send('a=100&b=200&c=300');
xhr.send('adfadsfa3er');
xhr.onreadystatechange = function(){
if(xhr.readyState === 4){
if(xhr.status >= 200 && xhr.status <300){
//logic
}
}
}```
AJAX请求--post请求
最新推荐文章于 2022-10-13 23:19:32 发布