Получение: статус 302 в Edge 17

Я использую js fetch API для получения данных из JSON. Он работает нормально (даже в IE 11), за исключением Edge 17, я получаю 302, заголовок ответа:

  • Длина содержимого: 0
  • Тип содержимого: текстовый / простой; charset = utf-8
  • Расположение: http://local.mysite.com/xxx

Мой локальный веб-сайт находится на Mac, я использую BrowserSync, чтобы сделать его доступным через 192.168.100.X: 3000 Затем я обновил файл hosts на моем ПК следующим образом:

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

Вот мой вызов:

   fetch('/fr/fil-actualites-json', { mode: 'cors' })
      .then(
        function(response) {
          console.info('code :' +response.status);
          if (response.status !== 200) {
            console.info('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.info('Fetch Error :-S', err);
      });

Спасибо за вашу помощь;)

Как сделать HTTP-запрос в Javascript?
Как сделать HTTP-запрос в Javascript?
В JavaScript вы можете сделать HTTP-запрос, используя объект XMLHttpRequest или более новый API fetch. Вот пример для обоих методов:
3
0
1 445
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

Safari выдавал эту ошибку:

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

Я нашел ответ:

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'
})

Другие вопросы по теме