0

I have json file on local like "D:\ABC\JsonFile\file.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);
        });
    });
GPService
  • 169
  • 1
  • 3
  • 10
  • You will probably find answer here : https://stackoverflow.com/questions/18637418/trying-to-load-local-json-file-to-show-data-in-a-html-page-using-jquery – SKJ Mar 06 '21 at 16:54

1 Answers1

2

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"

Tomasz Juszczak
  • 2,276
  • 15
  • 25
  • This is correct, you can only access files through http servers and not locally as you have set OP. – fared Mar 06 '21 at 17:34