php - Kendo AutoComplete doesn't work -


i have problem kendo autocomplete. trying search word, not work.

i try see through console of google chrome, error show me this:

"uncaught typeerror: cannot read property 'slice' of undefined"

this code:

html

<head>  <script src="librerias/jquery.min.js"></script>     <script src="librerias/kendo.all.min.js"></script>  </head>   <body> <input id="#autocomplete" /> </body> <script> 'use strict';  (function($, kendo) {     // select input , create autocomplete    $("#autocomplete").kendoautocomplete({        datasource: new kendo.data.datasource({            transport: {                read: "functions/autocomplet.php"            },            schema: {                data: "data"            }        }),        datatextfield: "nombre",        placeholder: "please select state"    });  })(jquery, kendo); </script> 

php

<?phpinclude ("conexion.php");   $arr = array(); $q=$_get["startswith"]; if (!$q) return;  $sql="select nombre clientes nombre '%q%'";  $stmt = mysql_query($sql,$conexion); while($row = mysql_fetch_array($stmt)) {     $arr[] = $row['nombre']; }  // add header line specify content type json header("content-type: application/json");  echo "{\"data\":" .json_encode($arr). "}";?> 

when create autocomplete, invokes transport.read there no startswith argument exits without returning anything.

you should either return empty array:

if (!$q) {     echo "{\"data\":" .json_encode($arr). "}";     return; } 

or define autocomplete not send request until there minimum number of characters typed using minlenght:

$("#autocomplete").kendoautocomplete({     datasource   : new kendo.data.datasource({         transport: {             read: "autocomplet.php"         },         schema   : {             data: "data"         }     }),     minlength    : 1,     datatextfield: "nombre",     placeholder  : "please select state" }); 

by default, autocomplete not use serverfiltering means expects return php code , client filters it. should do:

$("#autocomplete").kendoautocomplete({     datasource   : new kendo.data.datasource({         serverfiltering: true,         transport      : {             read: "autocomplet.php"         },         schema         : {             data: "data"         }     }),     minlength    : 1,     datatextfield: "nombre",     placeholder  : "please select state" }); 

next, typed string not sent startswith parameter little more complex string, filter: { logic: "and", filters: [ { field: "nombre", operator: "startswith", value: "typed" } ] }. if don't want parse it, can use parametermap , autocomplete definition like:

$("#autocomplete").kendoautocomplete({     datasource   : new kendo.data.datasource({         serverfiltering: true,         transport      : {             read        : "autocomplet.php",             parametermap: function (op) {                 return { startswith: op.filter.filters[0].value };             }         },         schema         : {             data: "data"         }     }),     minlength    : 1,     datatextfield: "nombre",     placeholder  : "please select state" }); 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -