I'm trying to create an autocomplete search bar that implements an XML file that I created. I'm following the XML demo on jQuery. My script is as follows:
$(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 );
}
});
}
});
});
The XML file has the following format:
<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>
The search bar isn't returning anything though. There's no autocomplete working.
All help is appreciated