Numm3n
Numm3n

Reputation: 1031

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. Cookies are required for my page due to authentication.

The request is on the same domain, and I don't see any reason why it shouldn't. I use https.

This doesnt work in Firefox/Edge (No cookies set):

    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):

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

Upvotes: 0

Views: 447

Answers (2)

Numm3n
Numm3n

Reputation: 1031

I forgot that I need to set { 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;
    });
});

Upvotes: 1

Sujit Agarwal
Sujit Agarwal

Reputation: 12508

As per the browser support list, IE does not support fetch - you can check the support here on this link.

Upvotes: 0

Related Questions