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

153
Views
Cómo hacer que el texto/identificación que doy se pueda traer de la URL que estoy solicitando

Necesito escribir una ID (del 1 al 10) y que se muestre en una tabla, pero no sé cómo llevar la ID que escribí a la impresión, ¿cómo visualizo SOLO los datos de cierta ID del archivo json? ?

 <label for="ide">ID:</label> <input id="ide" type="search" placeholder="ID" name="ide"> <button id="boton" type="submit">Buscar</button> <table class="table bordered"> <thead> <tr> <th>UserID</th> <th>ID</th> <th>Title</th> <th>Completed</th> </tr> </thead> <tbody id="tabla"> </tbody> </table>
 function ajax() { const url = "https://jsonplaceholder.typicode.com/users"; axios.get(url) .then((res) => { show(res.data) }) .catch((err) => { console.log(data); }) } function show(data) { for (const id of data) { tabla.innerHTML += ` <tr> <td>${id.id}</td> <td>${id.name}</td> <td>${id.username}</td> <td>${id.email}</td> </tr> ` } } document.getElementById("boton").addEventListener("click", function() { ajax(); });
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Declarar una variable para id primero

 let id = 0 document.getElementById("ide").addEventListener("onchange", function(e) { id = e.target.value });

Su función ajax debería ser así:

 function ajax() { const url = `https://jsonplaceholder.typicode.com/users/:${id}`; axios.get(url) .then((res) => { show(res.data) }) .catch((err) => { console.log(data); }) }
over 4 years ago · Santiago Trujillo 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!