Forked from Ihabafia/jQuery: AutoComplete CodeIgniter
Created
September 16, 2017 19:27
-
-
Save amad4biz/6453cdca1b2f59b79a85a5b5365f17a1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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