axios 跨域 [英] cross domain at axios

查看:25
本文介绍了axios 跨域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 axios 更改 jquery ajax,但我没有将 axios 用于跨域:

I am changing jquery ajax for axios and I not getting use axios with cross domain:

axios.get(myurl, {
            headers: { 'crossDomain': true },
        }).then(res => { 
            console.log(res);

        }).catch(error => {
            console.log('erro', error);
        })

我的 jquery 代码正在运行:

My jquery code is working:

$.ajax({
   type: 'GET',
   crossDomain: true,
   url:myurl,
   success: (res) => {},
   error: (fail) => {}     
})

错误:预检响应中的 Access-Control-Allow-Headers 不允许请求标头字段 crossDomain.

The error: Request header field crossDomain is not allowed by Access-Control-Allow-Headers in preflight response.

有人可以帮我吗?

推荐答案

"crossDomain" 不必出现在标题中

"crossDomain" does not have to be in headers

axios.get(myurl, {
    crossDomain: true
}).then(res => { 
    console.log(res);
}).catch(error => {
    console.log('error', error);
})

问候

这篇关于axios 跨域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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