Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
pass json outside async function

Im trying to pass the jason variable outside an async function, the function is inside a module, and I want to access it with a separate javascript file

<script type="module" src="./build/main.js"></script>

main.js (getSpatialStructure returns a json)

const output_1 = document.getElementById("message_r");

const init = async () => {
  const modeloo = await viewer.IFC.loadIfcUrl(ifcURL);
  let ifcInfo = await viewer.IFC.getSpatialStructure(modeloo.modelID);
  let json_ifc_data = ifcInfo;
  output_1.innerHTML = JSON.stringify(ifcInfo, null, 2);

}

init();

separate js

<script type="text/javascript">

json_ifc_data = ?

</script>

Ive been trying to acces it through the innerhtml

$(document).ready(function() {

    var jjson_sc = document.getElementById("message_r").innerHTML;
    console.log(jjson_sc);

    var jjson = document.getElementById("json_esp");
    jjson.innerHTML = jjson_sc;
  });

or setting the parameter outisde the async function

let json_ifc_data;

const init = async () => {
  const modeloo = await viewer.IFC.loadIfcUrl(ifcURL);
  let ifcInfo = await viewer.IFC.getSpatialStructure(modeloo.modelID);
  let json_ifc_data = ifcInfo;
  output_1.innerHTML = JSON.stringify(ifcInfo, null, 2);

}

init();

but both cases the value is undefined

thanks

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda