首页 > 解决方案 > 网站页面加载时如何调用 API?

问题描述

我需要一些帮助。所以,我想调用这个 API 并在我的网站上显示它给出的文件

这是链接:

https://gramcloud.com/api/download/061b78fb83ee928748b78bc7ee9f3e98

它生成:

{
  "download_link": "http://ogramcloud.com/static/files/Fly_Me_to_the_Moon_Evangelion_OST.mp3", 
  "file_key": "061b78fb83ee928748b78bc7ee9f3e98", 
  "message": "file restored successfully !", 
  "status": "success"
}

我需要调用它并在我的网站上显示http://ogramcloud.com/static/files/Fly_Me_to_the_Moon_Evangelion_OST.mp3为。<audio>

我该怎么做呢?

标签: javascripthtmlapidomfrontend

解决方案


你可以用它jQuery来做到这一点:

$(function () {
  $.get("https://ogramcloud.com/api/download/061b78fb83ee928748b78bc7ee9f3e98", function (response) {
    link = JSON.parse(response).download_link
    // append a <source> to your <audio> or do whatever you want with the link
  })
})

推荐阅读