I search all questions about typeahead plugin in this forum and have tried all the ways i can. But i have a problem yet. Im using codeigniter and want to autocomplete by typeahead plugin via ajax. This is my js code:
$('.typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
}, {
source: function (query, process) {
$.ajax({
url: baseUrl + 'panel/yazilarim/deneme',
type: 'POST',
data: 'query=' + query,
dataType: 'JSON',
async: true,
success: function (data) {
console.log(data);
process(data);
}
});
}
});
public function deneme() {
$aranan = $this->input->post("query");
$sorgu = $this->db->select("ad")->from("kategori")->where("ad LIKE '%" . $aranan . "%' ")->get();
$sonuclar = $sorgu->result_array();
$dizi = [];
foreach ($sonuclar as $sonuc) {
$dizi[] = $sonuc["ad"];
}
echo json_encode($dizi);
}
console.log()
function works well, i can see the result array, but the dropdown menu never appears. I've load bundle and typeahead js files and the css file. Any suggestions?
This is how i implemented typeahead in my CodeIgniter project. Please refer the my working code. In the view page
In the controller
I think your controller is right. If it doesn't work please comment the problem below.Remember i use get method.