IT虾米网

ajax之axios跨域

luoye 2025年12月25日 程序员 23 0

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

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

我的 jquery 代码正在运行:

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

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

谁能帮我吗?

请您参考如下方法:

“crossDomain”不必位于 header 中

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

问候


评论关闭
IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!