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(...);