js fetch函数怎么鎐ookie,并且下次请求时带 cookie 访问

js fetch函数怎么鎐ookie,并且下次请求时带 cookie 访问
最新回答
浅沫记忆

2026-02-26 09:19:34

增加credentials: 'include',参数即可带cookie发请求

示例:
fetch('./api.php?action=getJson', {
method: 'POST',
credentials: 'include',
headers:{
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'test=test'
})