Вы должны вызвать запрос в Yahoo Weather API, вы, кажется, оставили это. Запрос теперь установлен на *, чтобы он мог возвращать другие данные, кроме ветра. Кроме того, в запрос присваивается переменная var location для охвата всех регионов. Используйте название штата для областей в США, шт. Нью-Йорк в городской коробке, в коробке.
<!DOCTYPE html>
<html>
<head>
<script>
function getLocation() {
var city = document.getElementById("city").value;
var country = document.getElementById("country").value;
var location = city + "," + country;
//create a script and add it to your page
var script = document.createElement('script');
script.src = "https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (select woeid from geo.places(1) where text='" + location + "')&format=json&callback=callbackFunction";
document.getElementsByTagName('head')[0].appendChild(script);
}
var callbackFunction = function(data) {
var wind = data.query.results.channel.wind;
var wind_chill = wind.chill;
var wind_speed = wind.speed;
var wind_direction = wind.direction
document.getElementById("chill").innerHTML = wind_chill;
document.getElementById("speed").innerHTML = wind_speed;
document.getElementById("direction").innerHTML = wind_direction;
//alert(wind.chill);
}
</script>
</head>
<body>
City:<input type="text" id="city">
Country/State in U.S.A<input type="text" id="country">
<input type="button" onclick="getLocation()" value="Get Weather">
<p>Wind Chill</p>
<p id="chill"></p>
<p>Wind Speed</p>
<p id="speed"></p>
<p>Wind Direction</p>
<p id="direction"></p>
</body>
</html>
Автор Brian Glaz помог мне с этим, показывая мне, как назначить расположение уага на запрос и как вызвать запрос после того, как данные вводятся.
и в чем ваш вопрос? произошла ошибка ? – Raptor
@Raptor жаль, что не упоминал об этом раньше. Я думаю, что забыл что-то здесь. Https://gist.githubusercontent.com/ydn/6ef5a695e871b8a628d0/raw/weather.js –
Он не показывает текущий холод ветра, и я не знаю, куда положить недостающую информацию. –