【问题标题】:fetching from openweathermap api从 openweathermap api 获取
【发布时间】:2021-12-31 11:17:47
【问题描述】:

尝试从 OpenWeatherMap API 获取数据,然后尝试在控制台中显示它,但响应是不包含数据的 HTML 页面,响应状态为 200...它应该是 JSON 我在邮递员中尝试了 API,它有效并且显示了正确的数据,但在这里它不断抛出 Uncaught (in promise) SyntaxError: Unexpected token

const Fetching = async () => {
  const response = await fetch('api.openweathermap.org/data/2.5/weather?&q=London&appid=31c3627d9d33b84c7a575fc11b6d7dfe');
  const responsedata= await response.json();
  console.log(responsedata);
};
  Fetching();

【问题讨论】:

  • Unexpected token

标签: javascript html json fetch-api


【解决方案1】:

请修改您的网址,如下所示

 const Fetching = async () => {
        const response = await fetch('https://api.openweathermap.org/data/2.5/weather?&q=London&appid=31c3627d9d33b84c7a575fc11b6d7dfe');
        const responsedata = await response.json();
        console.log(responsedata);
    };

Fetching();

【讨论】:

  • 谢谢你的工作
猜你喜欢
  • 2018-08-22
  • 1970-01-01
  • 1970-01-01
  • 2018-05-17
  • 2021-07-28
  • 1970-01-01
  • 2019-04-23
  • 2021-03-08
  • 2016-11-28
相关资源
最近更新 更多