LiveNVR拉流视频流媒体平台如何解决JS_axios调用接口时遇到的跨域问题
@
1、JS调用遇到跨域解决示例
添加 xhrFields: { withCredentials: true},crossDomain: true,
$.ajax({
type: "GET",
url: "http://other-domain:10800/api/v1/login",
xhrFields: {
withCredentials: true
},
crossDomain: true,
data: {
username: 'test',
password: 'test'
},
success: function(data) {
console.log(data);
}
})
2、axios请求接口遇到跨域问题
添加 withCredentials: true
2.1、post请求
axios.post("http://ip:10800/api/v1/test", {
param1: 'test',
param2: 'test'
}, {
withCredentials: true
}).then(res => {
console.log(res)
}).catch(err => {
console.log(err);
})
2.2、get请求
axios.get("http://ip:10800/api/v1/test", {
params:{start:0,limit:10},
withCredentials: true
}).then(res => {
console.log(res)
}).catch(err => {
console.log(err);
})