我的桌面文件夹中有一个 json 文件,我尝试在 html 文件中访问,但出现以下错误。
XMLHttpRequest cannot load file://localhost/Users/p41technologies/Desktop/Json%20in%20Html/json-data.json. Origin null is not allowed by Access-Control-Allow-Origin.
我什至尝试过,
open -a "Google Chrome" --args --allow-files-access-from-files
和
open -a "Google Chrome" --disable-web-security
但是没有成功。我仍然遇到同样的错误。 为什么会出现这种情况以及如何解决。
最佳答案
您遇到的安全功能应该可以防止恶意脚本从本地文件系统读取。
您查看过html5 file/filereader api吗? ?有一个tutorial with working demos 。您也可以看看here .
关于javascript - XMLHttpRequest无法加载html中的本地桌面文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17648669/