- 最近下載easyui的demo到本地看看效果,查看grid時頁面加載不出數據,報錯;
Access to XMLHttpRequest at 'file:///E:/ExtendPlugIn/EasyUI/jquery-easyui-1.8.6/demo/datagrid/datagrid_data1.json' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.
截圖類似:
解決方法:
方法一:配置快捷方式目標參數
找到谷歌瀏覽器快捷鍵-右鍵-屬性-快捷方式-目標的后面輸入空格再加
–allow-file-access-from-files,再關閉所有chrome窗口,重啟chrome,再通過快捷鍵打開的瀏覽器輸入本地文件路徑
注意:allow前面有兩個“-”
方法二:把目標的值可以通過cmd中敲命令
方法三:新建bat文件
可以把在要敲的命令放進去新建一個bat文件里,雙擊就能打開chrome瀏覽器
踩坑記錄:
(1)目標在后面寫 --disable-web-security 無效
(2)目標在后面寫 --disable-web-security --user-data-dir 也無效
(3)目標在后面寫 --args --disable-web-security --user-data-dir 也無效
【參考】
https://zhuanlan.zhihu.com/p/130391287