简体   繁体   English

XMLHttpRequest无法在html中加载本地停止文件

[英]XMLHttpRequest cannot load local destop file in html

I have an json file in my desktop folder and i try to access in my html file but i get following error. 我的桌面文件夹中有一个json文件,我尝试访问我的html文件,但出现以下错误。

XMLHttpRequest cannot load file://localhost/Users/p41technologies/Desktop/Json%20in%20Html/json-data.json. XMLHttpRequest无法加载文件://localhost/Users/p41technologies/Desktop/Json%20in%20Html/json-data.json。 Origin null is not allowed by Access-Control-Allow-Origin. Access-Control-Allow-Origin不允许使用Origin null。

I even tryied to, 我什至试着

open -a "Google Chrome" --args --allow-files-access-from-files 打开-a“ Google Chrome浏览器” --args --allow-files-access-from-files

and

open -a "Google Chrome" --disable-web-security 打开-“ Google Chrome浏览器” --disable-web-security

but it didn't work. 但这没用。 I still get the same error. 我仍然遇到相同的错误。 Why does it happen and how to solve it. 为什么会发生以及如何解决。

the security feature you encountered is supposed to prevent malicious scripts to read from the local file system. 您遇到的安全功能应该可以防止恶意脚本从本地文件系统读取。

have you looked into the html5 file/filereader api ? 您是否研究了html5 file / filereader api there is a tutorial with working demos . 有一个工作演示教程 you may also have a look here . 你也可以在这里看看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM