5 <title>jQuery UI Autocomplete - XML data parsed once</title>
6 <link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
7 <script src="../../jquery-1.9.1.js"></script>
8 <script src="../../ui/jquery.ui.core.js"></script>
9 <script src="../../ui/jquery.ui.widget.js"></script>
10 <script src="../../ui/jquery.ui.position.js"></script>
11 <script src="../../ui/jquery.ui.menu.js"></script>
12 <script src="../../ui/jquery.ui.autocomplete.js"></script>
13 <link rel="stylesheet" href="../demos.css">
15 .ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }
19 function log( message ) {
20 $( "<div/>" ).text( message ).prependTo( "#log" );
21 $( "#log" ).attr( "scrollTop", 0 );
27 success: function( xmlResponse ) {
28 var data = $( "geoname", xmlResponse ).map(function() {
30 value: $( "name", this ).text() + ", " +
31 ( $.trim( $( "countryName", this ).text() ) || "(unknown country)" ),
32 id: $( "geonameId", this ).text()
35 $( "#birds" ).autocomplete({
38 select: function( event, ui ) {
40 "Selected: " + ui.item.value + ", geonameId: " + ui.item.id :
41 "Nothing selected, input was " + this.value );
51 <div class="ui-widget">
52 <label for="birds">London matches: </label>
56 <div class="ui-widget" style="margin-top:2em; font-family:Arial">
58 <div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div>
61 <div class="demo-description">
62 <p>This demo shows how to retrieve some XML data, parse it using jQuery's methods, then provide it to the autocomplete as the datasource.</p>
63 <p>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.</p>