I have the following data currently feeding JQuery Autocomplete
var network_autocomplete=[
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$( "#network" ).autocomplete({
source: network_autocomplete
});
I need to modify this to retrieve the array of results from a php page. Can somebody help me to modify this so I can in JavaScript do this?
network_autocomplete=data
Currently, the code retrieves data from an SQLite table in this manner:
try {
$db = new PDO('sqlite:/tmp/bacnet.db');
$query = "SELECT net, name, FROM network";
foreach ($db->query($query) as $row) {
$networks[] = array('net' => $row['net']);
}
echo json_encode($networks);
return json_encode($networks);
} catch (PDOException $e) {
echo json_encode(array('message' => 'Could not connect to the database'));
}
Change $networks[] = array('net' => $row['net']);
to$networks[] = $row['net'];
And you should not have return, unless this is a function (and if it's a function, why it has an echo?)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With