跨域問題

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
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章