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

我正在尝试使用 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"

},


元芳怎么了
浏览 241回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript