问题图片
问题描述
在练习js的过程中用到ajax,总是console出现报错:Access to XMLHttpRequest at ‘file:///Users/XXX/Downloads/nav/nav.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.
解决方法
解决思路:启用本地服务器打开即可
操作步骤(VScode为例):
1.VScode中启用插件:live sever
2.把项目文件放在同一个文件目录下,通过open with live sever的方式即可解决