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

285
Views
Cómo obtener varias URL GET a la vez
fetch(`./User.json`, { method: "get" }) .then(response => response.json()) .then(data => data.results.forEach(result => (list.innerHTML += template(result))) ) .catch(error => console.log(error));

Quiero agregar algunos datos json. cual es la solución. Ese es mi código.

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

0

Suponiendo que desea que se completen todas las solicitudes, independientemente de su estado de respuesta, entonces Promise.allSettled() es una excelente opción

 // handy "get" shortcut with error handling const get = async (url) => { const res = await fetch(url) // "GET" is the default method if (!res.ok) { throw new Error(`${res.status}: ${await res.text()}`) } return res.json() } const urls = ["./Foo.json", "./Bar.json", "./Baz.json"] Promise.allSettled(urls.map(get)).then(responses => { const data = responses .filter(({ status }) => status === "fulfilled") .map(({ value }) => value) })
about 4 years ago · Juan Pablo Isaza Report

0

Puede usar el método Promise.all para obtener los valores de las llamadas de búsqueda una vez que se hayan resuelto todas las promesas, obtendrá los valores en una matriz que puede destruir como se muestra a continuación

 Promise.all([fetch(`./User.json`, { method: "get" }).then(response => response.json())]), fetch(`./Products.json`, { method: "get" }).then(response => response.json())]).then([users, products]=> users.results.forEach(result => (list.innerHTML += template(result))) )

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!