我通常在 Flask(Web 框架)中使用 session ,一切正常。但是,当我在 javascript 中通过 fetch
发送 GET 请求时, session 似乎被清除(未保存)。背后的原因是什么?有什么方法可以解决这个问题吗?
最佳答案
下次您可以尝试fetch(url, {凭证:'same-origin'}),而不是简单地调用
:fetch(url)
:
credentials
: The request credentials you want to use for the request:omit
,same-origin
, orinclude
. To automatically send cookies for the current domain, this option must be provided. Starting with Chrome 50, this property also takes aFederatedCredential
instance or aPasswordCredential
instance.
—来自Fetch#Parameters (强调我的)
关于javascript - 为什么在 javascript 中使用 fetch 后 session 会被清除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38311982/