簡體   English   中英

Ajax下拉列表可使用Yahoo Weather搜索輸入以查找天氣

[英]Ajax dropdown list to search input to find weather using Yahoo Weather

我有此代碼,如果選擇該代碼,它將提供城市的下拉列表,以便為我提供該特定城市的天氣。 使用Yahoo API提取數據。

這是代碼,

<HTML>
<HEAD>
<TITLE>Find Weather in major cities around the worl</TITLE>
<META NAME="Keywords" CONTENT="ajax, weather, api, fetch, yahoo">
<META NAME="Description" CONTENT="yahoo, weather">
<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />
<SCRIPT type="text/javascript">
<!--

$(document).ready(function(){

function get_weather()
{
var p = $("#code").val();

var u = ($('#u').attr('checked')) ? '&u=c' : '';
var to_load = 'get_weather.php?p='+ p + u;

$("#weather").html('<img style="margin-top: 104px;" src="ajax-loader.gif"   align="absmiddle">');

$("#weather").load(to_load);
}

$(window).load(get_weather); // Trigger "get_weather" when the window loads

// Trigger "get_weather" when the form objects are used
$("#code").change(get_weather);
$("#u").click(get_weather); 
});

//-->
</SCRIPT>

</HEAD>

<BODY>

<A target="_blank" HREF=""></A>

<center>

<div align="center">

<h2 align="center">Find World Weather</h2>

<form>
Get Weather for: <select id="code" name="code">
<option value="AFXX0001">Ghurian</option>
<option value="AFXX0002">Herat</option>
<option value="UKXX0687">Buckingham, United Kingdom</option>
<option value="ASXX0001">Adelaide, Australia</option>
</select>

<input type="checkbox" id="u" name="u" value="c">&nbsp;Change to degrees Celsius
</form>

<div id="weather"></div>
</div>
</center>
</BODY>
</HTML>

但是我需要的是下拉列表位置的搜索框,當我輸入城市時,我應該獲取該位置的天氣信息。 我是一個初學者,所以請像這樣對待我,並簡化您的所有答案。 非常感謝。

我想您可能會為此感到困惑,因為您需要了解來自Yahoo的每個位置的WOEID。 從外觀上看,沒有簡單的方法可以通過編程的方式來實現。 我認為您最好使用其他天氣服務,例如http://api.openweathermap.org/data/2.5/weather?q=Birmingham,uk

看來他們會自己對地址進行地理編碼,但是您始終可以將Google地理編碼api與該服務結合使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM