跨域問題

fetch GET 跨域問題:前端

報錯信息nginx

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請求方法換成以下:json

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 )跨域

後臺代碼:fetch

Access-Control-Allow-Origin: 'http://www.zrt.local:8080'
Access-Control-Allow-Credentials: true
  • 前端代碼:
crossDomain: true, 
xhrFields: {
    withCredentials: true
}
相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息