天天看點

開啟chrome跨域模式--No 'Access-Control-Allow-Origin' header is present on the requested resource解決方案

前端在開發中經常會遇到跨域的問題,如果出現跨域,控制台會出現如下提示:

開啟chrome跨域模式--No 'Access-Control-Allow-Origin' header is present on the requested resource解決方案

關于跨域的原理,這裡就不詳談了,我們主要介紹chrome浏覽器怎麼設定允許跨域。這裡的方法使用于49版本以上,相信你的版本不會低于49啦,如果真是這麼低,就趕緊更新吧。

一、windows系統

1. 在你的在電腦上建立一個目錄,例如:C:\MyChromeDevUserData;

2. 在桌面找到你的chrome浏覽器圖示,右鍵--屬性,在屬性頁面中的目标輸入框裡加上   --disable-web-security --user-data-dir=C:\MyChromeDevUserData,--user-data-dir的值就是剛才建立的目錄。

3. 然後點選确定,關閉屬性界面。

啟動浏覽器,如果浏覽器出現了如下圖所示的提示,則配置成功了。

開啟chrome跨域模式--No 'Access-Control-Allow-Origin' header is present on the requested resource解決方案

二、mac系統

首先在你的電腦建立一個空的檔案夾,名字任取,如mychromeData,然後打開指令視窗,輸入:

open -n /Applications/Google\ Chrome.app/ --args --disable-web-security  --user-data-dir=/Users/hexiufeng/mychromeData

其中Users/hexiufeng/mychromeData就是你建立的檔案夾的位置。回車,然後打開chrome浏覽器,就可以看到跨域提示了。這是我們可以看到mychromeData檔案夾下已經生成了一對檔案:

開啟chrome跨域模式--No 'Access-Control-Allow-Origin' header is present on the requested resource解決方案

繼續閱讀