87,838
社区成员




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);
}
}
});
但是连接接口会出现:
那位大神能给解决一下也可以提一下方法谢谢!