1 | <!doctype html>
|
---|
2 | <html>
|
---|
3 | <head>
|
---|
4 | <title>jQuery UI Autocomplete Remote datasource demo</title>
|
---|
5 | <link type="text/css" href="../../themes/base/ui.all.css" rel="stylesheet" />
|
---|
6 | <script type="text/javascript" src="../../jquery-1.4.1.js"></script>
|
---|
7 | <script type="text/javascript" src="../../ui/jquery.ui.core.js"></script>
|
---|
8 | <script type="text/javascript" src="../../ui/jquery.ui.widget.js"></script>
|
---|
9 | <script type="text/javascript" src="../../ui/jquery.ui.position.js"></script>
|
---|
10 | <script type="text/javascript" src="../../ui/jquery.ui.autocomplete.js"></script>
|
---|
11 | <link type="text/css" href="../demos.css" rel="stylesheet" />
|
---|
12 | <script type="text/javascript">
|
---|
13 | $(function() {
|
---|
14 | function log(message) {
|
---|
15 | $("<div/>").text(message).prependTo("#log");
|
---|
16 | $("#log").attr("scrollTop", 0);
|
---|
17 | }
|
---|
18 |
|
---|
19 | $.ajax({
|
---|
20 | url: "london.xml",
|
---|
21 | dataType: "xml",
|
---|
22 | success: function(xmlResponse) {
|
---|
23 | var data = $("geoname", xmlResponse).map(function() {
|
---|
24 | return {
|
---|
25 | value: $("name", this).text() + ", " + ($.trim($("countryName", this).text()) || "(unknown country)"),
|
---|
26 | id: $("geonameId", this).text()
|
---|
27 | };
|
---|
28 | }).get();
|
---|
29 | $("#birds").autocomplete({
|
---|
30 | source: data,
|
---|
31 | minLength: 0,
|
---|
32 | select: function(event, ui) {
|
---|
33 | log(ui.item ? ("Selected: " + ui.item.value + ", geonameId: " + ui.item.id) : "Nothing selected, input was " + this.value);
|
---|
34 | }
|
---|
35 | });
|
---|
36 | }
|
---|
37 | })
|
---|
38 |
|
---|
39 | });
|
---|
40 | </script>
|
---|
41 | </head>
|
---|
42 | <body>
|
---|
43 |
|
---|
44 | <div class="demo">
|
---|
45 |
|
---|
46 | <div class="ui-widget">
|
---|
47 | <label for="birds">London matches: </label>
|
---|
48 | <input id="birds" />
|
---|
49 | </div>
|
---|
50 |
|
---|
51 | <div class="ui-widget" style="margin-top:2em; font-family:Arial">
|
---|
52 | Result:
|
---|
53 | <div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div>
|
---|
54 | </div>
|
---|
55 |
|
---|
56 | </div><!-- End demo -->
|
---|
57 |
|
---|
58 | <div class="demo-description">
|
---|
59 | <p>
|
---|
60 | This demo shows how to retrieve some XML data, parse it using jQuery's methods, then provide it to the autocomplete as the datasource.
|
---|
61 | </p>
|
---|
62 | <p>
|
---|
63 | 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.
|
---|
64 | </p>
|
---|
65 | </div><!-- End demo-description -->
|
---|
66 |
|
---|
67 | </body>
|
---|
68 | </html>
|
---|