我有两种类型的输入文本框,我需要用两种不同的数据源来完成。我的问题是其中一个工作正常,但第二个没有。这是我的代码:
$(document).ready(function () {
var cities = [];
$.ajax({
type: "GET",
url: "AIRPORTS.xml",
dataType: "xml",
success: parseXml,
complete: setupAC,
failure: function (data) {
alert("XML File could not be found");
}
});
function parseXml(xml) {
//find every query value
$(xml).find("AIRPORT").each(function () {
cities.push($(this).find("CITY").text() + ", " + $(this).find("COUNTRY").text());
}
});
}
function setupAC() {
$("input#cheapFlightList_cityLabel_0").autocomplete({
source: cities,
minLength: 1,
select: function (event, ui) {
$("input#cheapFlightList_cityLabel_0").val(ui.item.value);
$('#cheapFlightList_cityLabel_0').blur();
}
});
}
var airlines = [];
$.ajax({
type: "GET",
url: "AIRLINES.xml",
dataType: "xml",
success: parseXmlAirlines,
complete: setupACAirlines,
failure: function (data) {
alert("XML File could not be found");
}
});
function parseXmlAirlines(xml) {
//find every query value
$(xml).find("AIRLINE").each(function () {
airlines.push($(this).find("NAME").text());
});
}
function setupACAirlines() {
$("input#cheapFlightList_cityID_0").autocomplete({
source: airlines,
minLength: 1,
select: function (event, ui) {
$("input#cheapFlightList_cityID_0").val(ui.item.value);
$('#cheapFlightList_cityID_0').blur();
}
});
}
});
源cities
的工作正常,但源airlines
的工作正常。虽然航空公司阵列确实填满了航空公司名称。
我做错了什么?
修改
AIRPORTS.xml示例:
<?xml version="1.0" encoding="utf-8"?>
<AIRPORTCODES>
<AIRPORT>
<NAME>Aachen-Merzbruck</NAME>
<CITY>Aachen</CITY>
<COUNTRY>Germany</COUNTRY>
<ISO>DE</ISO>
<WAC>623</WAC>
<IATA>AAH</IATA>
</AIRPORT>
</AIRPORTCODES>
AIRLINES.xml示例
<?xml version="1.0" encoding="utf-8"?>
<AIRLINES>
<AIRLINE>
<NAME>ABSA Cargo Airline</NAME>
</AIRLINE>
</AIRLINES>
我已经使用在线验证器验证了xml,这很好。
编辑2
为我的工作输入生成的标记是:
<input name="cheapFlightList$ctrl0$cityLabel" type="text" value="Lahore" id="cheapFlightList_cityLabel_0" class="ui-autocomplete-input" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true">
为非工作文本框生成的标记为:
<input name="cheapFlightList$ctrl0$CityID" type="text" value="Aegean Airlines" id="cheapFlightList_CityID_0">