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
}
04-10 13:54