fetch请求接口方式

1
2
3
4
5
6
7
8
9
10
11
12
13
fetch('/api/getList',
{credentials: 'include',
//表示用户代理是否应该在跨域请求的情况下从其他域发送cookies
//omit:不发,same-origin:同源才发,include:不论是不是跨域的请求,总是发送请求资源域在本地的 cookies、 HTTP Basic authentication 等验证信息。
method: 'post', //请求方式
headers: {'content-Type':'application/json;charset=UTF-8'}, //设置请求header头
body:JSON.stringify({'prescriptionNumbers':'450','outpatientNumber':'1524450117626','patientId':'5000008149'})}) //参数传递 字符串
.then(res=>res.json()) //解析json
.then((data)=>{
console.log(data);
}).catch(err=>{ //捕获异常
console.log(err);
})
坚持技术分享,您的支持将鼓励我继续创作!