Fetch : status 302 in Edge 17

Viewed 1591

I'm using js fetch API to retreive datas from JSON. It's working fine (even in IE 11), except in Edge 17 i get 302, the response header are :

My local website is on a Mac, i'm using BrowserSync to make it reachable via 192.168.100.X:3000 Then i've updated my PC hosts file like this :

192.168.100.X  http://local.mysite.com

Here's my fetch call :

   fetch('/fr/fil-actualites-json', { mode: 'cors' })
      .then(
        function(response) {
          console.log('code :' +response.status);
          if (response.status !== 200) {
            console.log('Looks like there was a problem. Status Code: ' +
              response.status);
            return;
          }

          // Examine the text in the response
          response.json().then(function(data) {
            // do some stuff
          });
        }
      )
      .catch(function(err) {
        console.log('Fetch Error :-S', err);
      });

Thx for your help ;)

1 Answers

Safari was throwing this error :

unhandled promise rejection syntaxerror the string did not match the expected pattern

I found the answer:

The default value for credentials is "same-origin".

The default for credentials wasn't always the same, though. The following versions of browsers implemented an older version of the fetch specification where the default was "omit":

Firefox 39-60 Chrome 42-67 Safari 10.1-11.1.2 If you target these browsers, it's advisable to always specify credentials: 'same-origin' explicitly with all fetch requests instead of relying on the default:

fetch('/users', {
  credentials: 'same-origin'
})
Related