P粉1067114252023-08-22 15:30:15
In addition to @Khanetor's answer, for those who are dealing with cross-origin requests, you can use credentials: 'include'
Example JSON fetch request:
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
By default, Fetch does not use cookies. To enable cookies, do the following:
fetch(url, { credentials: "same-origin" }).then(...).catch(...);