Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

axios中get请求可以使用表单提交FormData吗?

前端新人,最近在做一个支付接口的对接,接口是get请求:
image.png

但是请求之后报has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
如图:image.png

询问对方开发人员,对方说是要使用表单提交,
image.png
我试了几种方法后还是报想同错误,请问各位大佬
使用axios的get请求如何进行表单提交?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

这是跨域,找后端人员,接口要设置Access-Control-Allow-Origin:'*'//或者$origion。
至于你说的表单类型:

var data = new FormData();
formData.append("username", "Groucho")
formData.append("password", "123")
axios({
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded'//表单类型
    },
    method: 'get',
    params : data 
})

axios本身还是ajax调用,和表单提交有些区别。
接口如果不愿意处理跨域,用js模拟表单的form结构添加到body中,添加完数据模拟点击表单按钮提交,再删除html。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...