php - jQuery ui autocomplete ipv4 -


i'm using jquery ui autocomplete helper in form. when try use search list of available ips never filter results, no matter number of characters (numbers) type returns complete list. how can correct it? using code http://jqueryui.com/autocomplete/#remote-with-cache json generated php file similiar (i have reduced number of results):

["192.168.3.2","192.168.3.3","192.168.3.4","192.168.3.5","192.168.3.6","192.168.3.7","192.168.3.8","192.168.3.9","192.168.3.10"]

[edit]

the form page code:

<!doctype html> <html lang="en">     <head>         <meta charset="utf-8" />         <title>jquery ui autocomplete - remote caching</title>         <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />         <script src="http://code.jquery.com/jquery-1.9.1.js"></script>         <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>         <link rel="stylesheet" href="/resources/demos/style.css" />         <style>             .ui-autocomplete-loading {                 background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat;             }         </style>         <script>             $(function() {                 var cache = {};                 $("#birds").autocomplete({                     minlength: 2,                     source: function(request, response) {                         var term = request.term;                         if (term in cache) {                             response(cache[ term ]);                             return;                         }                         $.getjson("tab-ip-autocomplete.php", request, function(data, status, xhr) {                             cache[ term ] = data;                             response(data);                         });                     }                 });             });         </script>     </head>     <body>         <div class="ui-widget">             <label for="birds">birds: </label>             <input id="birds" />         </div>     </body> </html> 

the php json code:

<?php include_once 'conn.php';  inet_ntoa(ipv4) :ipv4";  $autocomplete = "select * vteste;";  $sth = $dbh->prepare($autocomplete); $sth->bindparam(':ipv4', $ipv4, pdo::param_str); $sth->execute(); $sth->setfetchmode(pdo::fetch_assoc); $row = $sth->fetch();   /* gera json */  $arr = array();  while ($row = $sth->fetch()):     $arr[] = $row['ipv4']; endwhile;  $json = json_encode($arr); echo $json; ?> 

when using remote datasource, jqueryui autocomplete doesn't filter results - down script provides data send on matching results.

from http://api.jqueryui.com/autocomplete/#option-source:

the autocomplete plugin not filter results, instead query string added term field, server-side script should use filtering results. example, if source option set "http://example.com" , user types foo, request made http://example.com?term=foo. data can in same format local data described above.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -