简体   繁体   English

未使用JavaScript提取设置的Cookie

[英]Cookies not set using javascript fetch

If I use fetch() in javascript on my page, it doesn't send cookies in the request in Firefox and Edge, In Chrome it works perfectly. 如果我在页面上的javascript中使用了fetch() ,则它不会在Firefox和Edge中的请求中发送cookie,在Chrome中,它可以完美运行。 Cookies are required for my page due to authentication. 由于身份验证,我的页面需要Cookies。

The request is on the same domain, and I don't see any reason why it shouldn't. 该请求位于同一个域中,我看不出为什么不应该这样做。 I use https. 我使用https。

This doesnt work in Firefox/Edge (No cookies set): 这在Firefox / Edge中不起作用(未设置cookie):

    fetch('/kiaweb/notification/key')
    .then(function (res) {
        res.json().then(function (data) {
            self.apiKey = data.key;
        });
    });

but this works everywhere (all cookies set) (using jquery): 但这适用于所有地方(设置了所有cookie)(使用jquery):

    $.get('/kiaweb/notification/key' function(data) {
    self.apiKey = data.key;});

I forgot that I need to set { credentials: "same-origin" } . 我忘记了我需要设置{ credentials: "same-origin" }

The request would be : 该请求将是:

fetch('/kiaweb/notification/key',{ credentials: "same-origin" })
.then(function (res) {
    res.json().then(function (data) {
        self.apiKey = data.key;
    });
});

根据浏览器支持列表,IE不支持fetch -您可以在此链接上查看支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM