私が作成した XML ファイルを実装するオートコンプリート検索バーを作成しようとしています。jQuery の XML デモに従っています。私のスクリプトは次のとおりです。
$(function() {
function log( message ) {
$( "<div/>" ).text( message ).prependTo( "#log" );
$( "#log" ).attr( "scrollTop", 0 );
}
$.ajax({
url: "courses.xml",
dataType: "xml",
success: function( xmlResponse ) {
var data = $( "course", xmlResponse ).map(function() {
return {
value: $( "department_name", this ).text() + ", " +
( $.trim( $( "class_number", this ).text() ) || "(unknown course)" ),
id: $( "id", this ).text()
};
}).get();
$( "#results" ).autocomplete({
source: data,
minLength: 0,
select: function( event, ui ) {
log( ui.item ?
"Selected: " + ui.item.value + ", ID: " + ui.item.id :
"Nothing selected, input was " + this.value );
}
});
}
});
});
XML ファイルの形式は次のとおりです。
<courses>
<course id="1">
<department_name>ELEC</department_name>
<class_number>2001</class_number>
<section_number>001</section_number>
<professor>Chris, Michael</professor>
<class_title>Electrical Engineering Concepts</class_title>
<time_of_day>14:00-15:15</time_of_day>
<days_of_week>TuTh</days_of_week>
<building>Randalph Hall</building>
</course>
ただし、検索バーは何も返しません。オートコンプリートは機能しません。
すべての助けに感謝します