chrome报错【Access to XMLHttpRequest at ‘file:///ceshi.json’ from origin ‘null’ has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https】
原因: 浏览器(Webkit内核)的安全策略决定了file协议访问的应用无法使用XMLHttpRequest对象
解决:
- Windows:
设置Chrome的快捷方式属性,在“目标”后面加上–allow-file-access-from-files,注意前面有个空格,重新打开Chrome即可。
- Mac:
只能通过终端打开浏览器:打开终端,输入下面命令:open -a “Google Chrome” --args --disable-web-security然后就可以屏蔽安全访问了[ --args:此参数可有可无]