Heim > Fragen und Antworten > Hauptteil
P粉1067114252023-08-22 15:30:15
除了@Khanetor的答案之外,对于那些正在处理跨域请求的人来说,可以使用credentials: 'include'
示例的JSON fetch请求:
fetch(url, { method: 'GET', credentials: 'include' }) .then((response) => response.json()) .then((json) => { console.log('Gotcha'); }).catch((err) => { console.log(err); });
https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials
P粉8180888802023-08-22 15:21:43
默认情况下,Fetch不使用cookie。要启用cookie,请执行以下操作:
fetch(url, { credentials: "same-origin" }).then(...).catch(...);