How to download local json file?

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

In particular, using FF12, I need to have access to a local file for json data. It works fine on the server, but I would like to make this demo more portable.

$.ajax({ url: "../_assets/levelschema.json", complete: function (data) { Levels = data.levels; //... }, success: function (data) { // wont get called b/c files don't have 200 HTTP status }, async: false }); 

I tried to set it not async = false, but I get an error "Access to restricted URI". This is a safety feature. I really need a demo to work offline, without Internet access, and I would prefer that people using it should not have to install a web server. I would also prefer not to include all my data in HTML tags, as this data is subject to change.

+2
source share
3 answers

Well, JSON requests using AJAX work just fine, as long as your data files are down the path from your original HTML file. So I tried to rise to the level in _assets / directory. The solution is to move _assets to the current HTML directory for access.

In this case, you can use AJAX with async = false.

+1
source

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

+4
source

If the JSON file is located on your local computer, refer to it as follows:

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

You will have to add this line to your standalone project and delete it when it lives, but this is the best way to do this without server-side support. You will also have to remove the AJAX code for your demo, because it will not work on your local computer.

+1
source

Source: https://habr.com/ru/post/973966/


All Articles