Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
Cómo mostrar/renderizar datos de la API obtenida con la ayuda de async await

Tengo una función en la que obtengo datos de la API y los analizo en json.

En la segunda función, trato de insertar datos en un elemento DOM.

¿Dónde está el problema, por favor, y cómo representamos estos datos correctamente?

Primera función:

 // GET PUBLIC IP const getIp = async () => { const reqIp = await fetch("https://ipinfo.io/json?token=xxx") return reqIp.json() }

Segunda función:

 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>

El token está bien, los datos se muestran correctamente en la consola.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Ohh, demasiado redbull y muy poco sueño.

Muchas gracias muchachos.

Como escribieron en los comentarios, el problema estaba en el selector.

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

Asi funciona sin problemas

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!