我正在尝试获取NYT API,它工作得很好,我尝试将其添加到函数中,以便用户可以在单击按钮时调用获取函数,但出现此错误 TypeError:NetworkError。来获取资源,我尝试查找它,但是所有答案都不相关,功能:
const keywordVal = document.getElementById("keyword").value
fetch("https://api.nytimes.com/svc/search/v2/articlesearch.json?q=" + keywordVal + "&api-key=apikey")
.then(data => data.json())
.then(data => {
let count = 0;
const articleArray = data.response.docs;
for (const articles of articleArray) {
const headlines = articles.headline.main;
var ArticleLinks = articles.web_url
count += 1
createElement("h4", count + "." + "<p>" + headlines + "</p>")
createElement("a", ArticleLinks + "<hr> ", ArticleLinks)
console.log(ArticleLinks)
}
})
.catch(err => { console.log(`Error : ${err}`) });
}