How can I load a local json file?

后端 未结 3 1795
悲哀的现实
悲哀的现实 2021-01-15 14:07

Is there a way to configure firefox using about:config to allow local file access (for demo purposes)?

Specifically using FF12, I need to be able to

相关标签:
3条回答
  • 2021-01-15 14:48

    If the JSON file is on your local computer, access it like this:

    <script type="text/javascript" src="myFile.json"></script>

    You'll have to add that line to your offline project and remove it when it's live, but it's the best way to do it without any server-side assistance. You'll also have to remove your AJAX code for your demo, because it's not going to work on your local computer.

    0 讨论(0)
  • 2021-01-15 15:02

    You can flip the security.fileuri.strict_origin_policy preference in about:config. But that opens up some security holes; moving your JSON to be in a child directory of the directory the HTML is in is a much better idea.

    0 讨论(0)
  • 2021-01-15 15:08

    Ok, JSON requests using AJAX work just fine as long as your data files are down path from your originating HTML file. So I was trying to go up a level to _assets/ directory. The solution is to move _assets into the HTML current directory for access.

    You can use AJAX with async=false in this case.

    0 讨论(0)
提交回复
热议问题