且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

标头javascript中的Cookie错误“拒绝设置不安全的标头” Cookie”。

更新时间:2022-03-30 23:32:14

JavaScript无法显式设置Cookie标头。

JavaScript cannot set cookie headers explicitly.

您可以使用 document.cookie 当前来源设置cookie。

You can use document.cookie to set a cookie for the current origin.

您可以使用 withCredentials:true ,以便先前设置的cookie会与跨域Ajax请求一起发送。

You can use withCredentials: true so that previously set cookies will be sent with a cross-origin Ajax request.

无法将Cookie更改为与当前来源不同的来源。

There is no way to change the cookies a different origin from the current origin.

发出相同的原始请求之前,需要先设置 document.cookie

Since you are making a same origin request all you need to do is set document.cookie before you make the request.