Me pregunto si puedo llamar a variables fuera de getJSON, teniendo un sitio web multilingüe, el archivo json parece (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 }Tengo todos los getJSON, y me gustaría almacenar variables, para usarlas más adelante en la página, pueden ser mensajes de error para mostrar, o un menú, ...
$(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); // emptyLuego intente hacer que estas variables se usen:
/*** Some code goes here */ let choosefile = storeKeys.CHOOSE_FILE; if (!fileValue) { $('#loadingResult').html(choosefile); //End code