php - jquery autocomplete will not display data -
forgive me if not use correct terms, beginner @ , trying build own dynamic website. problem jquery autocomplete. cannot display data on webpage. have been reading forums , watching videos week. have tried dozens of scripts. nothing seems work.
this jquery works:
</style> <link rel="stylesheet" href="css/jquery-ui-1.11.4-themes- smoothness.css"> <script src="js/jquery-1.10.2.js"></script> <script src="js/jquery-ui-1.11.4-ui.js"></script> <script type="text/javascript"> $(function() { $( "#search_bars" ).autocomplete({ source: ['bob', 'ted', 'bruce', 'alice'], minlength: 2 }); }); </script>
here jquery not work:
<link rel="stylesheet" href="css/jquery-ui-1.11.4-themes-smoothness.css">
<script type="text/javascript"> $(function() { $( "#search_bars" ).autocomplete({ source: 'js/ajax.php', minlength: 2 }); }); </script>
here ajax.php code:
<?php include_once '../reviews.class2.php'; $reviews = new reviews(); echo json_encode($reviews->search_bars($_get['term'])); ?>
and finally, here reviews.class2.php code:
<?php require('connections/db_conn.php');?> <?php mysql_select_db($database_db_conn, $db_conn) or die("could not find db"); class reviews { public function _construct(){ $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'dbpassword'; $dbname = 'dbname'; mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname); } public function search_bars($name){ $data = array(); $sql = "select * listing name '%$name%' or city '%$name%' order name limit 10"; $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_array($result, mysql_assoc)){ $data[] = array("value" => $row['name'] . ' ' . $row['city']); } return $data; } }
when preview ajx.php page in browser, see json data this:
notice: undefined index: term in c:\xampp\htdocs\js\ajax.php on line 6 [{"value":"88?s dueling pianos hollywood"},{"value":"all stars sports bar , grill pompano beach"},{"value":"america?s backyard fort lauderdale"},{"value":"american rock restaurant bar , grill deerfield beach"},{"value":"b.e.d. miami beach"},{"value":"bamboo beach fort lauderdale "},{"value":"bamboo room lake worth"},{"value":"bardot miami"},{"value":"beach betty?s dania beach"}, {"value":"best cellar wilton manors "}]
the problem json data not showing in
please help!
i think had similar issue until overrode autocomplete styles...
<style type="text/css"> .ui-autocomplete { max-height: 150px; overflow-y: auto; overflow-x: hidden; font-size: 9pt; } * html .ui-autocomplete { height: 100px; } </style>
Comments
Post a Comment