首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenWeatherMap返回错误信息

OpenWeatherMap返回错误信息
EN

Stack Overflow用户
提问于 2022-01-21 22:08:12
回答 1查看 184关注 0票数 0

嗨,我正在使用OpenWeatherMap API测试这个JS函数,但是当我获取请求时,这个承诺会跳转到具有挂起状态的.then(),但是该API使用的是HTML。

这是我的密码:

代码语言:javascript
复制
function onSearch(city){
    fetch(`api.openweathermap.org/data/2.5/weather?q=London&appid=${ApiKey}&units=metric`)
      .then(response => response.json())
      .then(data => {
        console.log(data)
        if(data.main !== undefined){
          const city = {
            min: Math.round(data.main.temp_min),
            max: Math.round(data.main.temp_max),
            id: data.id,
            img: data.weather[0].icon,
            wind: data.wind.speed,
            temp: data.main.temp,
            name: data.name,
            logitude: data.coord.lon,
            latitude: data.coord.lat
          };
        }
      })
      .catch(e => console.log(e))
  }

下面是API响应

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content="Web site created using create-react-app"
    />
    <link rel="apple-touch-icon" href="/logo192.png" />
    <!--
      manifest.json provides metadata used when your web app is installed on a
      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
    -->
    <link rel="manifest" href="/manifest.json" />
    <!--
      Notice the use of  in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
    <title>Weather App</title>
  <script defer src="/static/js/bundle.js"></script></head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
  </body>
</html>

实际上这是我的index.html代码

对于如何解决这个问题,有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2022-01-21 23:39:53

检查深度--我的代码在抓取时丢失了"http://“在URL的开头”

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70808121

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档