从本地主机从 React-Redux 发出 HTTP 请求 [英] make a HTTP Request from React-Redux from localhost

查看:62
本文介绍了从本地主机从 React-Redux 发出 HTTP 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 React Redux 的新手,而且我已经做过了:

I am new to React Redux, and All I already did:

1) 激活我的后端服务器 (localhost:5000)

1) activate my backend server (localhost:5000)

2) 使用 npm start (localhost:8080) 激活我的前端服务器

2) activate my front-end server using npm start (localhost:8080)

3) 我试图通过使用

this.props.dispatch({type: ActionTypes.FILE_UPLOAD_REQUEST, email: this.state.email, file: this.state.policyFile});

4) 使用 atlas-saga,并调用与调度相关的服务函数:

4) Using atlas-saga, and call my service function associated with the dispatch :

let result = yield call(Atlas.uploadFile, action.email, action.file);

5) 定义函数为:

export const uploadFile = (email, file) =>{return fetch(`${BASE_URL}/v1/files/${email}/policies`, {方法:'POST',标头:{} ,正文:{'文件':文件}}).then(response => response.json())}

在我尝试在我的反应中运行一个函数(一个调用调度的函数)后,它给了我他们找不到路由的错误.这是来自控制台的错误消息.

After I try to run a function at my react( a function that calls the dispatch), it gives me errors that they cannot found the route. This is the error message from the console.

Fetch API 无法加载 https://api-staging.autoarmour.co/v1/files/fakeemail@gmail.com/policies.请求的资源上不存在Access-Control-Allow-Origin"标头.因此,不允许访问 Origin 'http://localhost:8080'.响应的 HTTP 状态代码为 500.如果不透明响应满足您的需求,请将请求的模式设置为no-cors"以在禁用 CORS 的情况下获取资源.

是的,我没有创建任何减速器,只是将上传文件的纯函数.谢谢

Yes, I did not create any reducer, just pure function that will upload a file. Thank you

推荐答案

我解决了,哇哦!!!错误消息意味着它根本没有在后端连接.您需要确保它已连接.我通过将我的 redux 连接到我的 react 组件来解决它.谢谢各位

I SOLVE IT, WOHOO!!! The error message means that its not connected at the backend side at all. You need to make sure that it is connected. I solve it by connecting my redux to my react component. Thanks guys

干杯!

这篇关于从本地主机从 React-Redux 发出 HTTP 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆