1 |
<!doctype html> |
2 |
<html lang="en"> |
3 |
<head> |
4 |
<meta charset="utf-8"> |
5 |
<title>jQuery UI Autocomplete - Remote datasource</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"> |
14 |
<style> |
15 |
.ui-autocomplete-loading { |
16 |
background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; |
17 |
} |
18 |
</style> |
19 |
<script> |
20 |
$(function() { |
21 |
function log( message ) { |
22 |
$( "<div>" ).text( message ).prependTo( "#log" ); |
23 |
$( "#log" ).scrollTop( 0 ); |
24 |
} |
25 |
|
26 |
$( "#birds" ).autocomplete({ |
27 |
source: "search.php", |
28 |
minLength: 2, |
29 |
select: function( event, ui ) { |
30 |
log( ui.item ? |
31 |
"Selected: " + ui.item.value + " aka " + ui.item.id : |
32 |
"Nothing selected, input was " + this.value ); |
33 |
} |
34 |
}); |
35 |
}); |
36 |
</script> |
37 |
</head> |
38 |
<body> |
39 |
|
40 |
<div class="ui-widget"> |
41 |
<label for="birds">Birds: </label> |
42 |
<input id="birds"> |
43 |
</div> |
44 |
|
45 |
<div class="ui-widget" style="margin-top:2em; font-family:Arial"> |
46 |
Result: |
47 |
<div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div> |
48 |
</div> |
49 |
|
50 |
<div class="demo-description"> |
51 |
<p>The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are bird names, displayed when at least two characters are entered into the field.</p> |
52 |
<p>The datasource is a server-side script which returns JSON data, specified via a simple URL for the source-option. In addition, the minLength-option is set to 2 to avoid queries that would return too many results and the select-event is used to display some feedback.</p> |
53 |
</div> |
54 |
</body> |
55 |
</html> |