LiveNVR拉流視訊流媒體平臺如何解決JS|axios呼叫介面時遇到的跨域問題
阿新 • • 發佈:2021-08-10
@
目錄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);
})