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

158
Visualizações
How to display / render data from fetched api with the help of async await

I have one function in which I get data from the API and parsing it to json.

In the second function, I try to insert data into a DOM element.

Where is the problem, please, and how do we render this data correctly?

Firt function:

// GET PUBLIC IP
const getIp = async () => {

    const reqIp = await fetch("https://ipinfo.io/json?token=xxx")
    return reqIp.json()

}

Second function:

document.addEventListener("DOMContentLoaded", async () => {
    const dataIp = await getIp()
    let ipAdress = document.querySelectorAll('.ip p')
    ipAdress.innerHTML = dataIp.ip
})

getIp()

DOM:

<div class="ip">
  <h5>Your IP Adress:</h5>
  <p></p>
</div>

The token is OK, the data is displayed correctly in the console.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Ohh, too much redbull and too little sleep.

Thank you very much guys.

As they wrote in the comments, the problem was in the selector.

document.addEventListener("DOMContentLoaded", async () => {
    const dataIp = await getIp()
    let ipAdress = document.querySelector('.ip p')
    ipAdress.innerHTML = dataIp.ip
})

getIp()

This is how it works without problems

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