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

254
Views
¿Cómo obtener datos de la API?

Quiero obtener datos (particularmente la capitalización de mercado) de la API y mostrarlos dentro de mi div. Pero mi html no muestra datos sobre la ejecución. ¿Qué podría estar haciendo mal?

 <text id="result"></text> <script> // API for get requests let fetchRes = fetch( "https://api.lunarcrush.com/v2?data=assets&key=n8dyddsipg5611qg6bst9&symbol=AVAX"); // fetchRes is the promise to resolve // it by using.then() method fetchRes.then((res) => res.json()) .then((result) => { console.log(result); document.getElementById('result').innerHTML = result.config.data.0.market_cap; }) .catch(error => { console.log(error); }) </script>
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Dos sugerencias:

  1. ¿Por qué no simplemente encadenar el .then() directamente al fetch() ?
  2. Parece que tiene un poco de confusión sobre cómo acceder a los datos en su estructura; lo que busca es result.data[0].market_cap .

 // API for get requests let fetchRes = fetch("https://api.lunarcrush.com/v2?data=assets&key=n8dyddsipg5611qg6bst9&symbol=AVAX") .then((res) => res.json()) .then((result) => { console.log(result); document.getElementById('result').innerHTML = result.data[0].market_cap; }) .catch(error => { console.log(error); })
 <text id="result"></text>

Aparte: probablemente debería invalidar su clave API que ha incluido aquí, ya que ahora está disponible públicamente y puede usarse para falsificar solicitudes para esta API.

about 4 years ago · Juan Pablo Isaza Report

0

Estoy usando jQuery Framework para hacer esto fácilmente. Verifique el código a continuación.

 <script> $.get( "https://api.lunarcrush.com/v2", { data: "assets", key: "n8dyddsipg5611qg6bst9", symbol: "AVAX" }, function (result){ data = JSON.parse(result); } ); </script>

Puede usar jQuery agregando el siguiente código en su etiqueta <head> .

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
about 4 years ago · Juan Pablo Isaza Report

0

Utilice result.config.data[0].market_cap; en lugar de result.config.data.0.market_cap;

 let fetchRes = fetch( "https://api.lunarcrush.com/v2?data=assets&key=n8dyddsipg5611qg6bst9&symbol=AVAX"); // fetchRes is the promise to resolve // it by using.then() method fetchRes.then((res) => res.json()) .then((result) => { console.log(result); document.getElementById('result').innerHTML = result.config.data[0].market_cap; }) .catch(error => { console.log(error); });
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!