我使用的前端源是端口5555上的ReactJS,后端是端口8888上的Rails。我试图通过使用以下命令从React的Rails中获取数据:
const url = 'http://localhost:8888/problems';
fetch(url)
.then(res => {
res.json();
})
.then(response => {
console.log(response);
})
.catch(error => {
console.log(error);
});
但是收到了我的消息:
Access to fetch at 'http://localhost:8888/problems' from origin 'http://localhost:5555' has been blocked by CORS policy: 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.
我不知道该错误。请帮助我修复它