hi i am using jquery autocomplete with codeigniter my reslut array is coming from database and i am sending back the array using json_encode(). but in response i am not able to show the values in the search but i get the empty reslut, means i get values but i am not able to display but values are coming i can see the empty lis, my data array is like this
[{"countryid":"1","countryname":"Afghanistan"},{"countryid":"2","countryname":"Albania"},{"countryid":"3","countryname":"Algeria"},{"countryid":"4","countryname":"American Samoa"},{"countryid":"5","countryname":"Andorra"}]
my model function is like this
public function search_countries($string)
{
$this->db->like('countryname', $string);
$query = $this->db->get('countries');
return $query->result_array();
}
my controller function is this
public function search_countries()
{
$string = $this->input->post('countryname');
$data = $this->user_m->search_countries($string);
$this->output->set_header('Content-Type: application/json; charset=utf-8');
echo json_encode($data);
}
and here is jquery function
$( ".country" ).autocomplete({
source: function( request, response ) {
$.post("signup/search_countries", {countryname: request.term}, function(data){
response(data, function( data ) {
return {
label: data.countryid,
value: data.countryname
}
});
});
}
});