php - Jquery ajax autocomplete plugin -
php - Jquery ajax autocomplete plugin -
hi found plugin best upto now. , want jquery plugin: tokenizing autocomplete text entry
but when tried create own php file doesnt works
my php file :
<?php $arr= array( array("id"=>1,"name"=>"ruby"), array("id"=>1,"name"=>"kritya") ); var_dump($arr); $json_response = json_encode($arr); $json_response = $_get["callback"] . "(" . $json_response . ")"; echo $json_response; ?> they gave me sample.php file had this:
<? # # illustration php server-side script generating # responses suitable utilize jquery-tokeninput # # connect database mysql_pconnect("host", "username", "password") or die("could not connect"); mysql_select_db("database") or die("could not select database"); # perform query $query = sprintf("select id, name mytable name '%%%s%%' order popularity desc limit 10", mysql_real_escape_string($_get["q"])); $arr = array(); $rs = mysql_query($query); # collect results while($obj = mysql_fetch_object($rs)) { $arr[] = $obj; } # json-encode response $json_response = json_encode($arr); # optionally: wrap response in callback function jsonp cross-domain back upwards if($_get["callback"]) { $json_response = $_get["callback"] . "(" . $json_response . ")"; } # homecoming response echo $json_response; ?> i dont want info database utilize array or info xml file when seek utilize on html page
<h2 id="theme">facebook theme</h2> <div> <input type="text" id="demo-input-facebook-theme" name="blah2" /> <input type="button" value="submit" /> <script type="text/javascript"> $(document).ready(function() { $("#demo-input-facebook-theme").tokeninput("/test.php", { theme: "facebook" }); }); </script> </div> it works fine when set website php file keeps on saying searching.... file defiantly there error array structure.
the main problem passing nestled arrays
$arr= array( array("id"=>1,"name"=>"ruby"), array("id"=>1,"name"=>"kritya") ); when plugin expects array wraps bunch of objects mysql_fetch_object command.
perhaps might work:
$arr=array(); $object = new stdclass(); $object->id = 1; $object->name = "ruby"; $arr[]=$object; $object = new stdclass(); $object->id = 1; $object->name = "kritya"; $arr[]=$object; php json jquery jquery-plugins
Comments
Post a Comment