进行 axios.get 调用时出现 CORS 错误 [英] CORS error while making axios.get call

查看:336
本文介绍了进行 axios.get 调用时出现 CORS 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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.

访问控制允许来源必须设置为*

访问控制允许标题必须设置为Origin、X-Requested-With、Content-Type、Accept

这篇关于进行 axios.get 调用时出现 CORS 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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