This scripts are used,
https://www.devbridge.com/sourcery/components/jquery-autocomplete/
I am using jQuery Autocomplete for searching users from my DB.
Below is controller which returns Json:
public function searchusers1() {
if ($_GET) {
$query = $this -> input -> get('query');
$searcharray = $this -> model_usermanage -> searchuser($query);
$a_json = array();
$a_json_row = array();
foreach($searcharray as $row) {
//$user_firstname = htmlentities(stripslashes($row['user_firstname']));
//$user_lastname = htmlentities(stripslashes($row['user_lastname']));
$user_email = htmlentities(stripslashes($row['user_email']));
//$a_json_row[user_firstname] = $user_firstname;
$a_json_row[user_email] = $user_email;
array_push($a_json, $a_json_row);
}
echo json_encode($a_json);
}
}
Below is my jQuery:
$('#reply_bcc').autocomplete({
serviceUrl: '<?php echo base_url(); ?>index.php/hi/test/searchusers1',
minChars: 3,
onSelect: function (suggestion) {
console.log('You selected: ' + suggestion.data + ', ' + suggestion.data);
}
});
Here is my JSON response:
[{user_email:[email protected]},{user_email:[email protected]},{user_email:[email protected]},]
My HTML:
<div class=col-md-10>
<input type=text name=reply_bcc id=reply_bcc autocomplete=off class=form-control>
</div>
My PROBLEM is:
I am getting below error in console and I can not see this searched values as dropdown in my html input:
Uncaught TypeError: Cannot read property 'length' of undefined
What's going wrong with this?
Thanks!