js请求接口的时候有两个接口第一个接口可以正常请求但是第二个接口会报CORS怎么解决 那位大神能给一下解决方法!

ᝰꫝꪉꪯꫀ625 2023-10-17 15:25:05

js请求接口的时候有两个接口第一个接口可以正常请求但是第二个接口会报CORS怎么解决 那位大神能给一下解决方法!

代码

$.ajax({
    url: 'http://dtms.i-daeshin.cn:60082/api/Account',
    type: 'GET',
    data: {
        userName: 'xxx',
        password: 'Dx123789'
    },
    success: function (response) {
        var token = response.data.Token;
        $.ajax({
            url: 'http://dtms.i-daeshin.cn:60082/api/Car_Info',
            type: 'GET',
            data: {
                token: token,
                structid: '',
                carNo: 1,
                carType: '',
                cargoType: '',
                AreasId: ''
            },
            headers: {
                Authorization: 'Bearer ' + token // 将token添加至请求头
            },
            success: function (response) {
                // 请求成功的处理逻辑
                console.log(response);
            },
            error: function (xhr, status, e) {
                // 请求失败的处理逻辑
                if (xhr.status === 401) {
                    console.log('未经授权,请重新登录');
                } else if (xhr.status === 404) {
                    console.log('未找到请求的资源');
                } else {
                    console.log(e);
                }
            },
        });
    },
    error: function (xhr, status, e) {
        if (xhr.status === 401) {
            console.log('未经授权,请重新登录');
        } else if (xhr.status === 404) {
            console.log('未找到请求的资源');
        } else {
            console.log(e);
        }
    }
});

但是连接接口会出现:

 那位大神能给解决一下也可以提一下方法谢谢!

 

...全文
936 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

87,974

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧