javascript - 网站页面加载时如何调用 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>
我该怎么做呢?
解决方案
你可以用它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
})
})
推荐阅读
- python - Tkinter 传递参数
- amazon-web-services - AWS SAM samconfig.toml 文件未使用 --config-env 获取自定义环境
- c++ - 模板内定义的友元函数的实例化
- node.js - 从 VS Code 外部获取 VS Code ${workspaceFolder} 变量?
- r - 在R中分配函数取决于参数的值
- tensorflow - 估计二维表面温度网格
- python - 如何读取索引列表并返回多维 numpy 数组的值?
- android - 未处理的异常:PlatformException(无法运行模型,解释器忙,java.lang.RuntimeException:解释器忙于颤动
- c - 为什么 Openmp Conversion Works 但尝试 openmpi 显示错误
- xamarin.android - 编码 1256 数据找不到