获取两个URL Java脚本

发布于 2025-01-21 10:12:15 字数 987 浏览 3 评论 0原文

如何从此数组调用数据? 我必须添加其他URL的两个值。 在此处输入图像描述

<table id="sales_table">
  <thead>
    <tr id="sales_item_title"></tr>
  </thead>
  <tbody>
    <tr id="sales_item"></tr>
  </tbody>
</table>
<script>
  async function init(){
  try{
      const results = await Promise.all([

        fetch('https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=PLN').then((response)=> response.json()),

        fetch('https://min-api.cryptocompare.com/data/all/coinlist')
        .then((response)=> response.json()),

      ].map(promise=>promise.catch(error=>console.error)));

      console.log(results);
      document.querySelector('#sales_item').innerHTML = results.0.PLN

    } catch (error) {
      console.error(error);
    }
  }
  init();
</script>

How to call data from this array??
I have to add two values from others urls.
enter image description here

<table id="sales_table">
  <thead>
    <tr id="sales_item_title"></tr>
  </thead>
  <tbody>
    <tr id="sales_item"></tr>
  </tbody>
</table>
<script>
  async function init(){
  try{
      const results = await Promise.all([

        fetch('https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=PLN').then((response)=> response.json()),

        fetch('https://min-api.cryptocompare.com/data/all/coinlist')
        .then((response)=> response.json()),

      ].map(promise=>promise.catch(error=>console.error)));

      console.log(results);
      document.querySelector('#sales_item').innerHTML = results.0.PLN

    } catch (error) {
      console.error(error);
    }
  }
  init();
</script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧时模样 2025-01-28 10:12:15

您返回两个对象,并且可以通过键访问对象。在您的示例中。然后使用:object.pln

async function init() {
    const first = await fetch('https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=PLN')
    .then((response)=> response.json());

    const second = await fetch('https://min-api.cryptocompare.com/data/all/coinlist')
     .then((response)=> response.json());

    let merged = {...first, ...second};
    console.log(merged);    
    console.log('PLN:',merged.PLN)
}

init()
    .catch(e => {
        console.log('some problems: ' + e.message);
    });

You return two objects and you have access to the object by key. In your example PLN . Then use : object.PLN.

async function init() {
    const first = await fetch('https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=PLN')
    .then((response)=> response.json());

    const second = await fetch('https://min-api.cryptocompare.com/data/all/coinlist')
     .then((response)=> response.json());

    let merged = {...first, ...second};
    console.log(merged);    
    console.log('PLN:',merged.PLN)
}

init()
    .catch(e => {
        console.log('some problems: ' + e.message);
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文