拨打axios.get时发生CORS错误 [英] CORS error while making axios.get call
问题描述
我正在使用axios在我的redux action.js文件中进行axios.get调用。
在我的组件中,此操作是在表单提交时执行的。
I'm using axios to make a axios.get call in my redux action.js file. In my component this action is performed on form submission.
我的状态为 200
我的控制台,但没有得到任何回应。
我遇到以下错误:
I'm getting status 200
in my console but not getting any response back.
I'm getting the following error:
所请求的资源上没有'Access-Control-Allow-Origin'标头。因此,不允许访问源'http:\localhost:3000'。
有人遇到过这种错误吗?太?
Has anybody came across such error too? Would you please share on how to resolve this.
推荐答案
问题不在于axios。问题出在服务器上。在提供数据时,必须在发送数据之前添加以下标头。
The problem is not with axios. The issue is with the server. When you serve up data you must add the following headers, before sending it.
Access-Control-Allow-Origin
必须设置为
*
Access-Control-Allow-Headers
必须为设置为
来源,X请求方式,内容类型,接受
这篇关于拨打axios.get时发生CORS错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!