Skip to content

Instantly share code, notes, and snippets.

@Narven
Created April 24, 2013 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Narven/5451293 to your computer and use it in GitHub Desktop.
Save Narven/5451293 to your computer and use it in GitHub Desktop.
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);
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment