html 如何将API调用的响应输出到页面中?

jecbmhm3  于 2022-12-09  发布在  其他
关注(0)|答案(1)|浏览(189)

I'm trying to use this node package to get Rainbow Six Siege player info but I cant get it to work. I'm trying to update the span with the profileStats span
Note: I got the package to work in just a normal node environment so that part of the code should work

// const R6 = require('r6s-stats-api')

document.getElementById('search').addEventListener('click', updater)

function updater() {
  var platform = document.getElementById('platform').value
  var name = document.getElementById('username').value
  // let ranked = await R6.rank(platform, name)
  let ranked = {
    url: 'https://r6.tracker.network/profile/xbox/Iner/',
    name: 'Iner',
    header: 'https://images-eds-ssl.xboxlive.com/image?url=wHwbXKif8cus8csoZ03RWwcxuUQ9WVT6xh5XaeeZD01lYI1.K4gGf7cqlZ1YM_tmW8qRVC.FFmMbdPQW96vXZsQwreP_gBgF_1gRNq_1MEYG.I_gg1USpTo.w7p9X9EFL3VbKuCqrVtHXWJWPFwdWjVZawugUn8OP8CdzeblMDQHhUJv42ods6makmoyftKW',
    kd: '1.33',
    kills: '9,762',
    deaths: '7,350',
    win_: '56.2%',
    wins: '967',
    losses: '753',
    time_played: '555h 23m 42s',
    matches: '1,721',
    kills_match: '5.67',
    kills_min: '0.29',
    mmr: 'K/D',
    rank: 'SILVER V',
    rank_img: 'https://imgur.com/NpBtpuL.png'
  };
  document.getElementById('profileStats').innerText = ranked
}
<form>
  <input id="platform" class="platform" type="text" placeholder="Platform" />
  <input id='username' class='username' type="text" placeholder="Username" />
  <br>
  <input type="button" value="Search" id="search" />
</form>

<span>Profile Stats: <span id="profileStats">stats</span></span>

Expected output:
Profile Stats: { url: 'https://r6.tracker.network/profile/xbox/Iner/', name: 'Iner', header: 'https://images-eds-ssl.xboxlive.com/image?url=wHwbXKif8cus8csoZ03RWwcxuUQ9WVT6xh5XaeeZD01lYI1.K4gGf7cqlZ1YM_tmW8qRVC.FFmMbdPQW96vXZsQwreP_gBgF_1gRNq_1MEYG.I_gg1USpTo.w7p9X9EFL3VbKuCqrVtHXWJWPFwdWjVZawugUn8OP8CdzeblMDQHhUJv42ods6makmoyftKW', kd: '1.33', kills: '9,762', deaths: '7,350', win_: '56.2%', wins: '967', losses: '753', time_played: '555h 23m 42s', matches: '1,721', kills_match: '5.67', kills_min: '0.29', mmr: 'K/D', rank: 'SILVER V', rank_img: 'https://imgur.com/NpBtpuL.png' }

mkshixfv

mkshixfv1#

你不能把一个原始的JavaScript对象转储到页面中,你需要用每个单独的属性来更新DOM,或者循环遍历它们。
第一个

相关问题