为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用javascript获取api以显示数据?

如何使用javascript获取api以显示数据?

元芳怎么了 2021-06-10 13:12:48
我正在尝试使用 javascript 构建一个 API,以从此 URL 获取数据以获取 json 数据: img, a, c 。但是下面的代码抛出了一个错误application.js:10 Uncaught (in promise) TypeError: data.forEachis not a function(为什么forEach没有定义方法)你能帮忙吗?谢谢var results = document.getElementById("results");fetch("https://www.mangaeden.com/api/list/0/")  .then(response => response.json())  .then((data) => {    data.forEach((result) => {      const movies = '<li><img src="' + result.im + '" alt=""><h3>' + result.a + '</h3><p>' + result.c + '</p></li>';      results.insertAdjacentHTML("beforeend", movies);    });  });{  "a": "shoujo-apocalypse-adventure",  "c": [    "Adventure",    "Drama",    "Psychological",    "Sci-fi",    "Seinen",    "Slice of Life",    "Tragedy"  ],  "h": 156,  "i": "5c410d31719a16035a4647cc",  "im": "4a/4a1f2a595e0e84e62f6ceddf3946274478928ca99e8df86bc6511b6e.png",  "ld": 1547822837.0,  "s": 2,  "t": "Shoujo Apocalypse Adventure"},
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 240 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信