So, I have to open my web app, like file. So the browser opens .html
file and at the adres bar protocol used is file://
. But at the script I have to open .json
file and load it to variable.
I have tried $.ajax
request with data type jsonp
, I have tried requirejs
who kind a load file but gets syntax error from json file so it doesnt load into variable. Same happens if I just do this
<script type="text/javascript" src="path/to/.json"></script>
Is there another way? App doesn't use PHP it needs to run from file://
protocol with not changing browser settings.
Thanks
Embed the data directly into the page.
There's no network, so it won't cause a performance penalty. It's static, so you don't lose the ability to generate it dynamically.
you can create a .js
file and adds the json
data to a var
and get access to that var
<script type="text/javascript" src="path/to/data.js"></script>
UPDATE .. EXAMPLE
var text = '{"employees":[' +
'{"firstName":"John","lastName":"Doe" },' +
'{"firstName":"Anna","lastName":"Smith" },' +
'{"firstName":"Peter","lastName":"Jones" }]}';