Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
Access to JS Object outside the function

I want print data from my JSON in HTML Code

<body>
    <div id="example"></div>
    <div id="testing"></div>
    <div id="demo"></div>
</body>
 
<script>
  
 loadDoc()
    
 function loadDoc() {
  const xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("demo").innerHTML =
      this.responseText;
    let data= JSON.parse(this.responseText);
    let example = document.querySelector('#example');
    example.innerHTML = JSON.stringify(data.lose[0]["Preis"]);    <---- here it works, i can change the innerHTML of "example"
    
    }
  };
     
  xhttp.open("GET", "lose.json");
  xhttp.send();

}

testing.innerHTML = JSON.stringify(data.lose[1]["Preis"])    <---- outside the function loadDoc() i dont got access to data and i cant use the JSON data.

</script>
    
    
</html>

missingreference

So my Question how can i get access to my JSON data outside this loadDoc() function, because i want to use multiple entries of the imported JSON in my HTML.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda