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

154
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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