I want to use a Jquery UI- Autocomplete.
Here is the method to use Autocomplete.
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$( "#tags" ).autocomplete({
source: availableTags
});
});
Here the array “availableTags” is defined. But I want to generate the autocomplete from a data source which is a server-side script which returns JSON data.can anyone help me to fit that data source to autocomplete??
Im using MVC architecture (Codeigniter) and using following method in controller to return the JSON data,
function supcode(){
$dataarray="";
$data=$this->Inventorymodel->supcode();
echo json_encode($data);
}
And I am fetching the data in model using following function,
function supcode(){
$finresult="";
$this->db->select('name');
$query = $this->db->get('supplier');
$result=$query->result_array();
foreach($result as $row){
$finresult[]=array(
'name' => $row['name']
);
}
return $finresult;
}
And here is the URL to the function supcode in controller,
“index.php/inventory/supcode”
Thanks in advance…..
try this
and replace
to