jQuery UI Autocomplete and CodeIgniter
Posted
by
Kere Puki
on Stack Overflow
See other posts from Stack Overflow
or by Kere Puki
Published on 2012-05-02T22:04:09Z
Indexed on
2012/09/11
9:38 UTC
Read the original article
Hit count: 202
I am trying to implement a simple autocomplete script using jQuery UI and CodeIgniter 2 but my model keeps telling me there is an undefined variable so I dont know if my setup is right.
My view
$(function() {
$("#txtUserSuburb").autocomplete({
source: function(request, response){
$.ajax({
url: "autocomplete/suggestions",
data: {
term: $("#txtUserSuburb").val()
},
dataType: "json",
type: "POST",
success: function(data){
response(data);
}
});
},
minLength: 2
});
});
My controller
function suggestions(){
$this->load->model('autocomplete_model');
$term = $this->input->post('term', TRUE);
$rows = $this->autocomplete_model->getAutocomplete($term);
echo json_encode($rows);
}
My Model
function getAutocomplete() {
$this->db->like('postcode', $term, 'after');
$query = $this->db->get('tbl_postcode');
$keywords = array();
foreach($query->result() as $row){
array_push($keywords, $row->postcode);
}
return $keywords;
}
There arent any errors except it doesn't seem to be passing the $term variable to the model.
© Stack Overflow or respective owner