简体   繁体   中英

How can i read local file from D drive in javascript

My requirement is to read the json file which contains some data and store in some other .js file.

I got task to read local file from local disk in Javascript , i have used file path like - D:\\json\\analytics.json.

(document).ready(){
($).getData("D:\json\analytics.json");

}

when i see in firebug it takes other url.

How I can do it, is it possible to read file from javascript.

I don't know javascript , i have seen some answer but i am not able to understand .

Need Solution , how I can achieve it. is there any other way to read file on jsp without using scriptlet . From server side , can send it on the jsp page.

I think Jaronmanda's answer won't work cause it will hit cross origin issue, see "Cross origin requests are only supported for HTTP." error when loading a local file .

As the page suggested, in general you need to serve that json file from a web service (same domain, or allow your domain to access), but it depends on what you really need to do. If you can control where that json file is stored, the easier way is to put that in a subdirectory of your html file, and do:

$(document).ready(function () {       
    $.get('<directory>/analytics.json', function (data) {
        // Do your stuff
    });
});

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