javascript - Devbridge JQuery Autocomplete not working with serviceUrl -


i trying implement devbridge autocomplete doesnt work ajax. works when use manual json object without php need data database. php code:

 <?php require_once "medoo.php"; $database = new medoo([     'database_type' => 'mysql',     'database_name' => 'elektriksikayet',     'server' => 'localhost',     'username' => 'root',     'password' => '',     'charset' => 'utf8',     'port' => '3307' ]); $return_arr = []; $keyword =  $_post['keyword']; $companies = $database->select('companies','company_name'); foreach ($companies $comp){     $row_array['label'] = $comp;     array_push($return_arr, $row_array); } echo json_encode($return_arr); ?> 

html code:

<html lang="en"> <head>     <meta charset="utf-8">     <title>title</title>     <script src="js/jquery.js"></script>     <script src="js/jquery-autocomplete.js"></script>     <script src="js/companyautocomplete.js"></script> </head> <body> <input type="text" id="autocomplete"/> </body> </html> 

js code

$(document).ready(function () {     $("#autocomplete").autocomplete({         serviceurl:'autocomplete.php', //tell script send requests         //callback show it's working         onselect: function(value){ alert('you selected: ' + value); }     }); }); 

your response should valid json , following format:

   {         suggestions: [             { "value": "united arab emirates", "data": "ae" },             { "value": "united kingdom",       "data": "uk" },             { "value": "united states",        "data": "us" }         ]     } 

it not seem returning has structure.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -