Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script src="http://demos.jquerymobile.com/1.4.5/js/jquery.js"></script>
- <script src="http://demos.jquerymobile.com/1.4.5/js/jquery.mobile-1.4.5.min.js"></script>
- <script>
- $( document ).on( "pagecreate", "#myPage", function() {
- $( "#autocomplete" ).on( "filterablebeforefilter", function ( e, data ) {
- var $ul = $( this ),
- $input = $( data.input ),
- value = $input.val(),
- html = "";
- $ul.html( "" );
- if ( value && value.length > 2 ) {
- $ul.html( "<li><div class='ui-loader'><span class='ui-icon ui-icon-loading'></span></div></li>" );
- $ul.listview( "refresh" );
- $.ajax({
- url: "http://main.xfiddle.com/code_94010918.php",
- dataType: "jsonp",
- crossDomain: true,
- data: {
- q: $input.val()
- }
- })
- .then( function ( response ) {
- $.each( response, function ( i, val ) {
- html += "<li>" + val + "</li>";
- });
- $ul.html( html );
- $ul.listview( "refresh" );
- $ul.trigger( "updatelayout");
- });
- }
- });
- });
- </script>
- <style>
- .ui-filter-inset {
- margin-top: 0;
- }
- </style>
- </head>
- <body>
- <div data-role="page" id="myPage">
- <h3>Cities worldwide</h3>
- <p>After you enter <strong>at least three characters</strong> the autocomplete function will show all possible matches.</p>
- <form class="ui-filterable">
- <input id="autocomplete-input" data-type="search" placeholder="Find a city...">
- </form>
- <ul id="autocomplete" data-role="listview" data-inset="true" data-filter="true" data-input="#autocomplete-input"></ul>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement