双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

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

ᝰꫝꪉꪯꫀ625 CSDN会员 ᝰꫝꪉꪯꫀ625 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

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);
        }
    }
});

但是连接接口会出现:

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

 

...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
ᝰꫝꪉꪯꫀ625 CSDN会员
JavaScript 87,983 成员 224,680 内容