"정의되지 않은 '0'속성을 읽을 수 없습니다."오류가 발생합니다. 문제를 찾을 수 없습니다. javascript 파일에 문제가 있다고 생각하지만 잘 보지 못했습니다. 스크립트를 두 번 작성했지만 여전히 js 파일에 문제가 있습니다.정의되지 않은 '0'속성을 읽을 수 없습니다.
HTML 파일
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8">
<title>FreeCodeCamp - Local Weather</title>
<script src="https://code.jquery.com/jquery-3.0.0.js"></script>
<script type="text/javascript" src="app.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<div id="main" class="text-center container">
<h1>FreeCodeCamp - Weather App</h1>
<div class="row" id="fade">
<div style="margin-top: 200px;">
<span id="city"></span>
<span id="country"></span>
<div id="weather"><img id="w-icon"><span id="temp"></span></div>
<span id="description"></span>
</div>
</div>
<div id="author">
<span> Created by Kaan Karaca</span><br>
<span><a href="http://github.com/h4yfans">@GitHub</a> </span><br>
<span><a href="https://www.freecodecamp.com/h4yfans">@FreeCodeCamp</a> </span>
</div>
</div>
</body>
</html>
자바 스크립트 파일에 코드를 너무 모든 호출이 작동 할 것이라고 믿고있다
$(document).ready(function() {
var cityId;
var city;
var unitsFormat = "metric";
var getWeatherInfo = function() {
$.getJSON("http://api.sypexgeo.net/json")
.done(function (locationData) {
cityId = locationData.city.id;
cityName = locationData.country.iso;
$.getJSON("http://api.openweathermap.org/data/2.5/weather?", {
id: cityId,
units: unitsFormat,
APPID: '610ae7b6406da76bb34ad4bb95cc3673'
})
.done(function (weatherDate) {
$("#w-icon").attr("src", "http://openweathermap.org/img/w/" + weatherDate.weather[0].icon + ".png");
$("#temp").text(Math.round(weatherDate.main.temp) + "°C");
$("#city").text(weatherDate.name + ",");
$("#country").text(cityName);
$("#description").text(weatherDate.weather[0].description);
});
});
}
getWeatherInfo();
});
[정의되지 않은 객체의 속성을 감지]의 사용 가능한 복제 (http://stackoverflow.com/questions/27509/detecting-an-undefined-object-property) – cnorthfield
약 당신이 확실 'weatherDate.weather [0] .description'? 'console.log (weatherDate);를 사용한다면 무엇을 보여줄까요? –
디버거 (또는 콘솔 로그)를 사용하여 'weatherDate'가 보유하고 있다고 생각하는 값을 보유하고 있는지 확인 했습니까? ajax 호출에서 반환 된 실제 값을 게시해야합니다. 당신 * 코드 *는 맞을 수 있지만 당신의 * 데이터 *는 틀릴 수 있습니다. –