Created
April 24, 2013 10:51
-
-
Save Narven/5451293 to your computer and use it in GitHub Desktop.
jquery ui autocomplete / codeigniter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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