首页 > 解决方案 > react-redux 桌面应用程序中请求的资源错误中不存在 Access-Control-Allow-Origin' 标头

问题描述

我正在从 API 获取数据,但它没有用。它给了我这样的错误" Access to fetch at 'http://muslimsalat.com/lahore/false/5.json?key=API_KEY' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. "

当我在 react-native 移动设备中获取数据时,它可以工作,但是当我在 react 桌面中获取数据时,它无法正常工作。

谁能告诉我这个错误的原因是什么,我该如何解决?

标签: reactjsapireduxreact-reduxfetch

解决方案


将 CORS 添加到 API URL。您只需将本地 IP 添加到后端服务 (API)。如果您需要适当的代码让我们知道您使用哪种语言作为后端 API。


推荐阅读