Hi,
I am trying to implement an autocomplete textbox whose values are generated by a remote script returning XML contents. I'm using JQuery-1.4.3 and the autocomplete widget from JQuery-UI-1.8.5.
I've studied the autocomplete demo page for the XML data parsed once example, and am trying to implement the comments:
This should also serve as a reference on how to parse a remote XML datasource - the parsing would just happen for each request within the source-callback.
As a test, I'm trying to get this working with the supplied XML demo. Above comment suggests that the autocomplete 'source' property has to be replaced with the Ajax call. Yet, when I modify this in the function supplied at the demo page, I'm not getting any results with following autocomplete function:
$( "#birds" ).autocomplete({
source: function(request, response) {
$.ajax({
url: "london.xml",
dataType: "xml",
success: function( xmlResponse ) {
var data = $( "geoname", xmlResponse ).map(function() {
//alert($('name', this).text());
return {
value: $( "name", this ).text() + ", " +
( $.trim( $( "countryName", this ).text() ) || "(unknown country)" ),
id: $( "geonameId", this ).text()
};
}).get();
}
})
},
minLength: 0,
select: function( event, ui ) {
log( ui.item ?
"Selected: " + ui.item.value + ", geonameId: " + ui.item.id :
"Nothing selected, input was " + this.value );
}
});
Still, commenting out the simple debug popup message shows that the Ajax call does manage to retrieve the values used in constructing the data. Where's my mistake?
Any help much appreciated!
Kind regards,
Ron Van den Branden