My intension is to search users. But the autocomplete is not working for me. I would like some help on this.
Here are my codes,
HTML
<input id="user-input" type="text" name="users" placeholder="Search User" autocomplete="on">
Model
function get_user($user) {
$this->db->select('name');
$this->db->like('name', $user);
$query = $this->db->get('users');
// echo $query; die;
if($query->num_rows() > 0){
foreach($query->result_array() as $row) {
$row_set[] = htmlentities(stripslashes($row['name']));
}
echo json_encode($row_set);
}
}
Controller
public function user_search() {
$this->load->model('users_model');
if (isset($_GET['term'])){
$user = strtolower($_GET['term']);
$this->users_model->get_user($user);
}
}
Js
$(function(){
$("#user-input").autocomplete({
source: "site/user_search",
minLength: 1
});
});
I am using the jquery ui version 1.12