如何修复js fetch()有时不起作用



因此,如果我使用fetch api(而不是nodejs(并从api中提取数据,有时它不会请求任何数据,如果我检查网络选项卡,它会显示为空这里有一个的例子

fetch("https://api.aerisapi.com/earthquakes")
.then((Response) => Response.json())
.then((data) => console.log(data))

编辑:我修复了提取URL 中的空白

问题

当我在浏览器和js客户端中输入url时,我得到:

{"success":false,"error":{"code":"invalid_client","description":"A valid "client_id" and "client_secret" were not provided."},"response":[]}

小问题

  • 尝试使用async/await使fetch()的代码更可读。

  • 另一个次要的代码风格问题-正确的是:

    fetch("https://api.aerisapi.com/earthquakes")
    

在第一个"之后有一个空白

摘要

检查error,请返回一个完整的示例,其中包含隐藏的client_id和隐藏的secret,以便我可以测试它,并命名api所有者

前提条件

它必须是一个免费的api才能使用。

最新更新