getJson error “Not allowed to load local”

I have json file on local like “D:ABCJsonFilefile.json” and I need to read data in this file. When I run I got a error “Not allowed to load local” What wrong with my code?

This is my code.

     $("#GetJsonData").click(function () {
        $.getJSON("file://D:/ABC/JsonFile/jsondata.json", function (result) {
            console.log(result.ContentName);
        }).fail(function (jqXHR, txtStatus, errThrown) {
            console.log("Status : " + txtStatus);
            console.log("Error : " + errThrown);
        });
    });

Answer

I would assume this is client-side JS.

Because the browser should be considered as a “sandbox” you do not have permission to access the drive directly. You can only use URI to access files on other servers via HTTP.

For this, to work you need to host your file and use “https://yourserver.com/JsonFile/jsondata.json”

Leave a Reply

Your email address will not be published. Required fields are marked *