| 1 | <!doctype html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta charset="utf-8"> |
| 5 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 6 | <title>jQuery UI Autocomplete - Remote JSONP datasource</title> |
| 7 | <link rel="stylesheet" href="../../themes/base/all.css"> |
| 8 | <link rel="stylesheet" href="../demos.css"> |
| 9 | <style> |
| 10 | .ui-autocomplete-loading { |
| 11 | background: white url("images/ui-anim_basic_16x16.gif") right center no-repeat; |
| 12 | } |
| 13 | </style> |
| 14 | <script src="../../external/requirejs/require.js"></script> |
| 15 | <script src="../bootstrap.js"> |
| 16 | function log( message ) { |
| 17 | $( "<div>" ).text( message ).prependTo( "#log" ); |
| 18 | $( "#log" ).scrollTop( 0 ); |
| 19 | } |
| 20 | |
| 21 | $( "#birds" ).autocomplete({ |
| 22 | source: function( request, response ) { |
| 23 | $.ajax( { |
| 24 | url: "search.json", |
| 25 | dataType: "jsonp", |
| 26 | data: { |
| 27 | term: request.term |
| 28 | }, |
| 29 | success: function( data ) { |
| 30 | response( data ); |
| 31 | } |
| 32 | } ); |
| 33 | }, |
| 34 | minLength: 2, |
| 35 | select: function( event, ui ) { |
| 36 | log( "Selected: " + ui.item.value + " aka " + ui.item.id ); |
| 37 | } |
| 38 | } ); |
| 39 | </script> |
| 40 | <script src="../search.js"></script> |
| 41 | </head> |
| 42 | <body> |
| 43 | |
| 44 | <div class="ui-widget"> |
| 45 | <label for="birds">Birds: </label> |
| 46 | <input id="birds"> |
| 47 | </div> |
| 48 | |
| 49 | <div class="ui-widget" style="margin-top:2em; font-family:Arial"> |
| 50 | Result: |
| 51 | <div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div> |
| 52 | </div> |
| 53 | |
| 54 | <div class="demo-description"> |
| 55 | <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> |
| 56 | <p>The datasource is a server-side script which returns JSONP data, specified via a function which uses <code>jQuery.ajax()</code> for the <code>source</code> option.</p> |
| 57 | </div> |
| 58 | </body> |
| 59 | </html> |