javascript - XMLHttpRequest无法加载html中的本地桌面文件

标签 javascript html macos

我的桌面文件夹中有一个 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/

相关文章:

javascript - JS如何实现回文

javascript - 是否可以使用 HTML、CSS 和 Javascript 来创建可以访问 Iphone 蓝牙配对的 Iphone 应用程序?

html - CSS Sticky Footer Menu - 检查元素时布局损坏

html - Safari 中不显示带有圆形切口的叠加层

c - 在c程序中,为什么osx中的字符串(从strcpy复制)的释放内存不可用?

javascript - PHP 和 Ajax : Illegal invocation

javascript - d3.js 加载后强制布局自动缩放/缩放

java - 无法使用JSP从mySQL数据库获取数据

python - 我在通过 pip 使用终端下载 slycot 库时遇到问题

MacOS 使用应用程序打开文件 : where does it go to?