0

I want to load a JSON file locally into my HTML page, without using a web server. This isn't possible with AJAX so I came up with this solution:

HTML:

<script src="../js/hack.js"></script>
<script src="../js/data.json"></script>

Inside hack.js :

var myJsonData = 

And the json file looks like this:

[{"something":"anything"},{},{}]

I expected that the ultimate result would be this:

var myJsonData = [{"something":"anything"},{},{}]

But sadly I get the error: Uncaught SyntaxError: Unexpected end of input after loading 'hack.js'.

Is there any way to solve this without adjusting the json file, and without adjusting the local browser settings / using a localhost server?

Kokodoko
  • 26,167
  • 33
  • 120
  • 197

1 Answers1

1

You will have to change your json file so that you declare the variable there.

data.json

var MyjsonData = [{"something":"anything"},{},{}]

Now in your hack.js file, you can call the variable MyjsonData.

Jerodev
  • 32,252
  • 11
  • 87
  • 108
  • Thanks, that's probably the only solution. I was hoping for a way to avoid altering the JSON file itself. – Kokodoko Sep 30 '14 at 11:55