【发布时间】:2012-01-26 13:15:51
【问题描述】:
我有一个与AccuWeather API 一起使用的字符串列表,名为WeatherLocationDatabase.txt,看起来有点像这样:
CityName="Aachen, DE" Location="EUR|DE|GM011|AACHEN" Country="Germany"
CityName="Aalborg, DK" Location="EUR|DK|DA007|AALBORG" Country="Denmark"
CityName="Aalesund, NO" Location="EUR|NO|NO007|AALESUND" Country="Norway"
CityName="Aare, SE" Location="EUR|SE|SW006|AARE" Country="Sweden"
CityName="Aarhus, DK" Location="EUR|DK|DA001|AARHUS" Country="Denmark"
CityName="Aba, NG" Location="AFR|NG|NI008|ABA" Country="Nigeria"
CityName="Abadan, IR" Location="MEA|IR|IR016|ABADAN" Country="Iran"
CityName="Abakan, RU" Location="ASI|RU|RS033|ABAKAN" Country="Russia"
CityName="Abbotsford, CA" Location="NAM|CA|BC|ABBOTSFORD" Country="Canada"
CityName="Abeokuta, NG" Location="AFR|NG|NI000|ABEOKUTA" Country="Nigeria"
CityName="Aberdeen, UK" Location="EUR|UK|UK002|ABERDEEN" Country="United Kingdom"
CityName="Abidjan, CI" Location="AFR|CI|IV002|ABIDJAN" Country="Ivory Coast"
...
有没有办法使用 AJAX 来填充一个使用 jQuery 应该看起来像这样的 <select>?
<select>
<option value="CityName">CityName</option>
<option value="CityName">CityName</option>
<option value="CityName">CityName</option>
<option value="CityName">CityName</option>
...
</select>
【问题讨论】:
-
如果该列表是 XML 格式。
-
当然,只要看看 [previous question][1] [1] 中的这个例子:stackoverflow.com/questions/815103/…
-
那个问题是指格式良好的 JSON。这家伙看起来像是有一个逗号分隔的列表。你能格式化这个文本文件来准备它吗?还是其他东西的输出?
标签: jquery ajax regex list populate