Can't retrieve data from the NY Times API

后端 未结 2 1590
暖寄归人
暖寄归人 2021-01-07 10:46

I\'m trying to get the largest image, title, short description and url of top stories from the NY Times API. Before I get

2条回答
  •  自闭症患者
    2021-01-07 11:38

    Have a look at this. I answered in your dupe but here is better

    let html = [];
    fetch('https://api.nytimes.com/svc/topstories/v2/science.json?api-key=yourApiKey')
      .then((resp) => resp.json())
      .then(function(data) {
        data.results.forEach(res => {
          html.push(`

    ${res.title}

    `); }) document.getElementById("res").innerHTML = html.join(""); })

提交回复
热议问题