script.js 920 Bytes
Newer Older
EnesKarakas's avatar
EnesKarakas committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function getData() {
  const city = document.getElementById("city").value;
  const start = document.getElementById("start").value;
  const end = document.getElementById("end").value;
  const storageOption = document.getElementById("storage").value;
  const formatOption = document.getElementById("format").value;

  const apiKey = "1244099aeaee4b179e6111803241304";
  const apiUrl = `https://api.weatherapi.com/v1/current.json?key=${apiKey}&q=${city}&aqi=no`;

  fetch(apiUrl)
    .then((response) => {
      if (!response.ok) {
        throw new Error("Network response was not ok");
      }
      return response.json();
    })
    .then((data) => {
      // Wetterdaten anzeigen
      document.getElementById("weatherData").innerText = JSON.stringify(
        data,
        null,
        2
      );
    })
    .catch((error) => {
      console.error("There was a problem with the fetch operation:", error);
    });
}