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

177
Views
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 answers
Answer question

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