How to use JSON as config file with Javascript
something like
var cfg = {};
$.ajax({
url: myUrl,
async: false,
success: function(data) {
cfg = JSON.parse(data);
}
});
If you don't want to use an asynchronous call you can always assign a variable to the config object and put the file in the src
of a script tag
var appConfig={
'Lang' : 'EN',
'URL' : '/over/dose/app'
}
.
<script src="/path/to/config.js"></script>
<script> alert(appConfig.URL);</script>
Advantage is immediate loading. Possible disadvantage is it isn't a json file any more, it is regular javascript file in case you are writing to it from server code.
Of course this also creates a global variable.