Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read local JSON file (no web-server) with JavaScript

It seems that this has been asked a number of times, but I would like to make sure there are still no other alternatives.

So what I need to do is:

  1. Generate a .JSON file from .net (easy)
  2. Read the local JSON file with JavaScript and produce an html page with useful graphs etc (using Raphaeljs).
  3. Deliver the outcome (HTML + associated JavaScript) to the client.

I wouldn't mind installing a local Apache to read the JSON file easily but since I cannot ask the client to do this, I am looking for a way to read a local JSON file (on the filesystem, no web server) with JavaScript, so that I eventually provide the client with the HTML, .js and .json and he can see the associated graphs.

I 've been reading that FileReader class is an option but I want to have the flexibility to support these on a number of IE browsers (let say IE7 to IE10).

Any help on how to work round this would be much appreciated.

like image 794
theohar Avatar asked Dec 10 '12 15:12

theohar


1 Answers

Web browsers are not able to read files from the file system due to security reasons. If I've understood correctly, you have a .NET application running on the local machine?

If this is the case, you can host a WCF service to serve the JSON from your application. WCF self-hosting is described on this MSDN page. You should be able to make AJAX requests from the browser to a server hosted within you application on localhost.

like image 127
jevakallio Avatar answered Oct 01 '22 05:10

jevakallio