在JS中使用fetch函数发送请求,不需要额外引入链接
btns[3].onclick = function(){
fetch('http://127.0.0.1:8000/fetch-server',{
//请求方法
method:'POST',
//请求头
headers:{
id:100000
},
//请求体
body:'username=admin&password=admin'
}).then(reponse => {
//返回数据以text方式呈现
return reponse.text();
//返回数据以json格式呈现
//return reponse.json();
}).then(response => {
console.log(reponse);
});
}