0

I switched my AJAX request code to...

return fetch("computerssuck?" + qs)
            .then(res => res.json())
            .then(data => {

                ...
            })
            .catch(err => console.log(err));

And now it returns 302 and no response.

When I request the same page using the browser or using XMLHttpRequest it works and returns 200 and some JSON.

Why does Fetch not work?

Here is the original code...

xhr.open('get', "computerssuck?" + qs, true);

xhr.onload = function () {

    ...

}.bind(this);

xhr.send();

Both sets of code work locally on my dev machine.

Chrome says, "Failed to load response data." in the inspector and some JSON parsing code crashes.

Ian Warburton
  • 15,170
  • 23
  • 107
  • 189

1 Answers1

0

fetch doesn't send an authentication cookie by default.

Solution is here... Fetch API with Cookie

Ian Warburton
  • 15,170
  • 23
  • 107
  • 189