fetch GET 跨域問題:
報錯信息
Failed to load http://XXX.XXX.mobi:8000/conf/ui/nginx.json: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://192.168.1.33:8000' is therefore not allowed access.
將GET請求方法換成如下:
return fetch(url)
.then(response => {
return response.json()
})
.then(response => {return response})
.catch(e => console.log("Oops, error", e))
AJAX跨域問題:(參考:https://blog.csdn.net/sansan_7957/article/details/79714486 )
後臺代碼:
Access-Control-Allow-Origin: 'http://www.zrt.local:8080'
Access-Control-Allow-Credentials: true
- 前端代碼:
crossDomain: true,
xhrFields: {
withCredentials: true
}