An example of response data is as follows:
[ { "label":"Some Label", "value":"Some Value" }, { "label":"Some Label", "value":"Some Value" }, { "label":"Some Label", "value":"Some Value" }, { "label":"Some Label", "value":"Some Value" } ]
JS code:
function city_value() { return '/ajax/get_address_list?city_code='+$('#code').val(); } $("#currency_prefix").autocomplete({ source: city_value, minLength: 2, autoFocus: false, delay: 500, select: function (event, ui) {
Controller:
function get_address_list(){ $post_code= $this->input->get("city_code",true); $location_list = $this->ajax_m->m_get_address_like($post_code); $data = array(); foreach($location_list as $list_location) { $data[] = array( 'label' => $list_location->singapore_postal_code,
Model:
function m_get_address_like($city_code){ $this->db->select('singapore_address, singapore_postal_code'); $this->db->like('singapore_postal_code', $city_code,'after'); $this->db->or_like('singapore_address', $city_code,'after'); $q = $this->db->get('uhd_singapore_address'); if($q->num_rows() > 0) { foreach($q->result() as $row) { $data[] = $row; } return $data; } return false; }
I have not tested this yet. Try it yourself. Add a comment if any error occurs, otherwise enjoy coding.
source share