event.preventDefault(); // 기본 동작 방지 (페이지 이동 막기)
전체보기 리스트에서 첫번째 더보기 클릭시 발생하는 에러를 수정하면 될 듯 한데, 일단 카페 리스트 구현은 이제 슬슬 나를 힘들게한다...ㅋㅋㅋㅋ 여기에만 꽂혀서 다른 기능을 구현을 못하고있기도하니, 카페리스트 구현은 잠시 거리두기를 하고 날씨기능 구현을 시작해야겠다. 카페리스트는 며칠 후에 다시 건드려보자.
https://openweathermap.org/ 에서 회원가입 후 API Key를 발급받음.
jsp에 발급받아 놓은 API Key와, 도시를 변수로 세팅해주면 된다.
<script>
function fetchWeather() {
var city = "Daejeon";
var apiKey = "API Key";
var lang = "kr";
var apiUrl = "http://api.openweathermap.org/data/2.5/weather?q=" + city + "&appid=" + apiKey + "&lang=" + lang + "&units=metric";
fetch(apiUrl)
.then(function(response) {
return response.json();
})
.then(function(data) {
console.log(data); // 데이터를 콘솔에 출력
})
.catch(function(error) {
console.error('Error:', error);
});
}
</script>
<h1>Weather Information</h1>
<button onclick="fetchWeather()" style ="margin-top: 50px; margin-left: 50px;">Get Weather</button>

Get Weather 버튼을 클릭 후 콘솔을 확인하면 대전 날씨 데이터를 볼 수 있다!

["main"]["temp"]["main"]["humidity"]["weather"][0]["id"]OpenWeather에서는 weather condition을 ID 코드로 설정해놓는다.
날씨별 ID 코드 리스트 : https://openweathermap.org/weather-conditions
강수상태나 날씨상태는 ID 코드별로 묶어서 조건문을 만들 예정이다.
예를들어 ID가 200~599라면 비오는날에 가기 좋은 카페를 추천해주고 그에 맞는 이미지와 문구를 보여준다.
ID 200~299 : Thunderstorm (폭풍우)
ID 300~399 : Drizzle (이슬비)
ID 500~ 599 : Rain(비)
ID 600~699 : Snow (눈)
ID 700~799 : mist(안개)
ID 801~804 : Clouds (흐림)
ID 800 : Clear (맑음)
날씨 불러오기 테스트는 성공했으니 가공은 내일부터! 일단 좀 자자..