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

344
Views
La variable no está definida después de que deja el alcance de la función getJSON, ¿cómo solucionarlo?

Aquí está mi código:

 var my_json; $.getJSON("file.json", function(json) { my_json = JSON.stringify(json, null, 2); my_json = JSON.parse(my_json); console.log('in', my_json); // prints json }); console.log('after', my_json); // prints undefined

Estoy tratando de cargar ese archivo JSON, pero por alguna razón, la variable my_json se vuelve indefinida en el momento en que deja el alcance de la función getJSON. Cuando imprimo my_json en getJSON, se ve bien y tiene la información de JSON. La consola imprime esto: in (json object) y after undefined . Estoy bastante confundido acerca de esto. Las funciones buscar y requerir tampoco me han funcionado, por eso estoy usando esto. Cuando trato de usarlos, obtengo esto: Uncaught ReferenceError: require is not defined

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!