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

93
Visualizações
Async Function Not refreshing

This function works for a single data item but it should keep refreshing every few seconds. How does this repeat?

   async function get_iss() {
       const response = await fetch('https://api.wheretheiss.at/v1/satellites/25544');
       const data = await response.json();
       document.getElementById("ISSdata").innerHTML = data.altitude;
       Textbox1.value = data.longitude;
       Textbox2.value = data.latitude;
   }
   get_iss();>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

async function getIss() {
  // make request
  const response = await fetch('https://api.wheretheiss.at/v1/satellites/25544');
  const data = await response.json();
  // update UI
  document.getElementById("altitude").textContent = data.altitude;
  document.getElementById("lat").textContent = data.latitude;
  document.getElementById("lng").textContent = data.longitude;
}

document.addEventListener("DOMContentLoaded", function(event) {
  console.log("Starting requesting data...");
  // load data once
  getIss()
  // define interval
  const seconds = 2;
  // execute the function every x seconds (safe interval ID so we can stop the interval later)
  const interval = setInterval(getIss, seconds * 1000)

  // stop after 10 seconds here (just to not go overboard with requests here, you might not need this)
  setTimeout(() => {
    clearInterval(interval);
    console.log("Stopped requesting data.")
  }, 10 * 1000)
});
<div>
  <span>Altitude:</span>
  <span id="altitude"></span>
  <span>Lat:</span>
  <span id="lat"></span>
  <span>Lng:</span>
  <span id="lng"></span>
</div>

about 4 years ago · Juan Pablo Isaza Relatório
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