Very simple weather app
This commit is contained in:
+57
@@ -0,0 +1,57 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Weather App</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
margin: 0;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
.container {
|
||||
background-color: white;
|
||||
padding: 20px;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
input, button {
|
||||
margin: 10px 0;
|
||||
padding: 5px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Weather App</h1>
|
||||
<input type="text" id="cityInput" placeholder="Enter city name">
|
||||
<button onclick="getWeather()">Get Weather</button>
|
||||
<div id="weatherInfo"></div>
|
||||
</div>
|
||||
<script>
|
||||
function getWeather() {
|
||||
const city = document.getElementById('cityInput').value;
|
||||
fetch(`/weather?city=${encodeURIComponent(city)}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
const weatherInfo = document.getElementById('weatherInfo');
|
||||
weatherInfo.innerHTML = `
|
||||
<h2>Weather in ${city}</h2>
|
||||
<p>Temperature: ${data.temperature}°C</p>
|
||||
<p>Condition: ${data.condition}</p>
|
||||
`;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
const weatherInfo = document.getElementById('weatherInfo');
|
||||
weatherInfo.innerHTML = '<p>Error fetching weather data</p>';
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user