简体   繁体   English

html 文件中的 javascript 是否可以加载 json 文件数据?

[英]Any way a javascript in a html file with file:// origin can load a json file data?

I am building a html report that supposed to load from local disk.我正在构建一个应该从本地磁盘加载的 html 报告。 Like c:\report\index.html .c:\report\index.html

The local directory include the following files:本地目录包括以下文件:

c:\report\index.html
c:\report\data.json

I am trying to have javascripts in the html file load the data.json mentioned above, use JSON.parse .我试图让 html 文件中的 javascript 加载data.json上面提到的,使用JSON.parse Every techniques I use I get the error complains that the CORS policy forbids to load a json file from file:// even though I am trying to load it from the same directory location of the html file.我使用的每一种技术都会收到错误消息,即 CORS 策略禁止从file://加载 json 文件,即使我试图从 ZFC35FDC70D5FC69D269883A822C7A5E 文件的同一目录位置加载它。

I am hoping I don't have to give up on this approach since the result would be beneficial.我希望我不必放弃这种方法,因为结果将是有益的。 A simple report.html renders a sophisticated json data without the needs of any additional program or tool.一个简单的报告。html 无需任何其他程序或工具即可呈现复杂的 json 数据。 Just an existing chrome browser.只是一个现有的 chrome 浏览器。

Is there any possible to do this task?有没有可能做这个任务?

You have to first create another folder and name it example.json file.您必须首先创建另一个文件夹并将其命名为 example.json 文件。 after that you can easily data load.之后,您可以轻松地加载数据。 not json.parse不是 json.parse

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

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