Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2015
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.61 KB | None | 0 0
  1. <html>
  2.     <head>
  3.     <script src="http://demos.jquerymobile.com/1.4.5/js/jquery.js"></script>
  4.     <script src="http://demos.jquerymobile.com/1.4.5/js/jquery.mobile-1.4.5.min.js"></script>
  5.     <script>
  6.         $( document ).on( "pagecreate", "#myPage", function() {
  7.             $( "#autocomplete" ).on( "filterablebeforefilter", function ( e, data ) {
  8.                 var $ul = $( this ),
  9.                     $input = $( data.input ),
  10.                     value = $input.val(),
  11.                     html = "";
  12.                 $ul.html( "" );
  13.                 if ( value && value.length > 2 ) {
  14.                     $ul.html( "<li><div class='ui-loader'><span class='ui-icon ui-icon-loading'></span></div></li>" );
  15.                     $ul.listview( "refresh" );
  16.                     $.ajax({
  17.                         url: "http://main.xfiddle.com/code_94010918.php",
  18.                         dataType: "jsonp",
  19.                         crossDomain: true,
  20.                         data: {
  21.                             q: $input.val()
  22.                         }
  23.                     })
  24.                     .then( function ( response ) {
  25.                         $.each( response, function ( i, val ) {
  26.                             html += "<li>" + val + "</li>";
  27.                         });
  28.                         $ul.html( html );
  29.                         $ul.listview( "refresh" );
  30.                         $ul.trigger( "updatelayout");
  31.                     });
  32.                 }
  33.             });
  34.         });
  35.     </script>
  36.     <style>
  37.         .ui-filter-inset {
  38.             margin-top: 0;
  39.         }
  40.     </style>
  41. </head>
  42. <body>
  43.     <div data-role="page"  id="myPage">
  44.         <h3>Cities worldwide</h3>
  45.         <p>After you enter <strong>at least three characters</strong> the autocomplete function will show all possible matches.</p>
  46.         <form class="ui-filterable">
  47.             <input id="autocomplete-input" data-type="search" placeholder="Find a city...">
  48.         </form>
  49.         <ul id="autocomplete" data-role="listview" data-inset="true" data-filter="true" data-input="#autocomplete-input"></ul> 
  50.     </div>
  51. </body>
  52. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement