dimanche 26 mai 2019

How to fetch api with javascript to display data?

I am trying to build an API with javascript to fetch data from this url for jason data: img, a, c . But below codes threw back an error of

application.js:10 Uncaught (in promise) TypeError: data.forEach is not a function

(why is the forEach method not defined) can you help? thanks

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);

    });
  });


the Jason file:


{
      "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"
    }, 


Aucun commentaire:

Enregistrer un commentaire