I am wondering if I can call variables outside the getJSON, having a multilingual website, json file looks like (lang_fr.json, lang_en.json):
{
"HOME": "Home",
"ABOUT": "About",
"CONTACT": "Contact us",
"EMAIL": "E-mail Id",
"CHOOSE_FILE": "Please choose at least one file",
ETC
}
I all the getJSON, and would like to store variables, to use them later on the page, it can be error messages to display, or a menu,..
$(document).on('click', '#upload', function () {
// some code goes here
$.getJSON('cdns/json/lang_' + memLang + '.json', function (dlang) {
console.log(dlang);
var storeKeys = [];
var storeVals = [];
$.each(dlang, function(x, y){
storeKeys.push(x);
storeVals.push(y);
});
});
console.log(storeKeys); // empty
console.log(storeVals); // empty
Then try to get these variables to use down:
/*** Some code goes here */
let choosefile = storeKeys.CHOOSE_FILE;
if (!fileValue) {
$('#loadingResult').html(choosefile);
//End code