M
M
Mark2019-03-27 18:57:24
AJAX
Mark, 2019-03-27 18:57:24

Why does an error occur when processing an event?

import React from "react";
import Info from "./components/info";
import Form from "./components/Form";
import Weather from "./components/Weather";

const API_KEY = "";

class App extends React.Component {

gettingWeather = async (e) => {
  e.preventDefault();
  const api_url = await
  fetch(`api.openweathermap.org/data/2.5/weather?q=Kiev,ua&appid=${API_KEY}&units=metric`);
  const data = await api_url.json();
  console.log(data);
}


  render(){
    return (
        <div>
        <Info />
        <Form weatherMethod={this.gettingWeather} />
        <Weather />
        </div>
    );
  }
}

export default App;

Why does an error occur when a button is clicked? And how to solve it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-03-27
@marki1404

Maybe you should add something like https://to the beginning of the url you are trying to make a request to?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question