简体   繁体   中英

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. Like 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 . 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.

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. Just an existing chrome browser.

Is there any possible to do this task?

You have to first create another folder and name it example.json file. after that you can easily data load. not json.parse

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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