Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
Llamar a variables fuera de getJSON

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); // empty

Luego intente hacer que estas variables se usen:

 /*** Some code goes here */ let choosefile = storeKeys.CHOOSE_FILE; if (!fileValue) { $('#loadingResult').html(choosefile); //End code
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!