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

179
Vistas
I am trying to show my data obtained from my API but it is not shown I am consuming it with JS

I am trying to show my data obtained from my API but it is not shown I am using JS.

fetch (" http://127.0.0.1:8000/api/vehiculo/ ") .then (res => res.json ()) .then (data => muestraData (data))

const muestraData = (data) => {
   let body = '' 
   for (let i = 0; i <data.length; i ++) {
    body + = <tr><td>${data[i].id}</td></tr> 
   }
   document.getElementById('data').innerHTML = body
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

First of all, I don't know how your API response is look like, so in this explanation, I will use (Rick-and-Morty APIs).

https://rickandmortyapi.com/api/character

Let's make a function to fetch the data from API:

const loadData = () => {
  return fetch("https://rickandmortyapi.com/api/character")
    .then((response) => response.json())
    .catch((error) => {
      throw error;
    });
};

Now we can call loadData function and build the body:

const data = document.getElementById("data");

loadData().then((response) => {
  const results = response.results;
  let body = "";

  if (results && results.length > 0) {
    results.forEach((item) => {
      body += `ID: ${item.id} <br/>`;
    });
  }

  data.innerHTML = body;
});

Because the results variable contains an array of objects, we can just use the .forEach method.

loadData returns Promise

Working example:

https://codesandbox.io/s/affectionate-forest-utmr3

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