I'm using fetch API within my React app. The application was deployed on a server and was working perfectly. I tested it multiple times. But, suddenly the application stopped working and I've no clue why. The issue is when I send a get
request, I'm receiving a valid response from the server but also the fetch API is catching an exception and showing TypeError: failed to fetch
. I didn't even make any changes to the code and it's the issue with all of the React components.
I'm getting a valid response:
But also getting this error at the same time:
fetch(url)
.then(res => res.json())
.then(data => {
// do something with data
})
.catch(rejected => {
console.log(rejected);
});
When I remove credentials: "include", it works on localhost, but not on the server.
I tried every solution given on StackOverflow and GitHub, but it's just not working out for me.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…