Getting “TypeError: failed to fetch” when the request hasn't actually failed

前端 未结 5 1745
予麋鹿
予麋鹿 2020-12-01 09:05

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 stopp

5条回答
  •  一向
    一向 (楼主)
    2020-12-01 09:49

    The issue could be with the response you are receiving from back-end. If it was working fine on the server then the problem could be with the response headers. Check the Access-Control-Allow-Origin (ACAO) in the response headers. Usually react's fetch API will throw fail to fetch even after receiving response when the response headers' ACAO and the origin of request won't match.

提交回复
热议问题