jquery ui autocomplete / codeigniter
//needs jquery and jquery-ui
// auto complete
$( "#autocomplete-cities" ).autocomplete({
source: function(request, response) {
//console.info(request, 'request');
//console.info(response, 'response');
$.ajax({
//q: request.term,
url: "<?=site_url('geo/suggested_cities')?>",
data: { term: $("#autocomplete-cities").val()},
dataType: "json",
type: "POST",
success: function(data) {
//console.info(data);
response(data);
}
});
},
minLength: 2
});
/* PHP
function suggested_cities()
{
$term = $this->input->post('term');
$query = "SELECT id,accent_city FROM {$this->tbl_geo} WHERE accent_city LIKE '{$term}%' LIMIT 10";
$cities_data = $this->crud->run_query($query);
$cities = array();
foreach($cities_data->result_array() as $key):
$a = array(
'id' => trim($key['id']),
'label' => trim($key['accent_city']),
'value' => trim($key['accent_city'])
);
$cities[] = $a;
endforeach;
echo json_encode($cities);
}
*/