Welcome Guest, Not a member yet? Register   Sign In
result from autocomplete with ajax jquery json is not exactly

I use autocomplete jquery-ui. Results responsed but not exactly.

//-------------------- JS
$( "#code" ).autocomplete({ //the recipient text field with id #username
        source: function( request, response ) {
                url: "http://localhost:82/shop/backend/product/suggestions",
                dataType: "json",
                data: {term : $('#code').val()},
                success: function(data){
                    if(data.response == 'true') {
        minLength: 1

//-------------------- Controller
function suggestions()
        $term = trim($this->input->post('term',TRUE));
        $rows = $this->Product_model->get_auto_complete($term);
        $data = array();
        if (count($rows)>0) {
            $data['response'] = "true";
            $data['code'] = array();
            foreach ($rows as $row) {
                array_push($data['code'], $row['code']);
        else {
            $data['response'] = "false";
        $data['term'] = $term;
     echo json_encode($data);

//-------------------- Model
function get_auto_complete($code)
        $query = $this->db->get();        
        return $query->result_array();

In my table, i have code list : S0001, S0002, A0001, A0002
But, when i press key in code field, all are been showed.
Please help me this error !
Thanks !

in your model, after this line $query = $this->db->get(); add this new line which is
echo $this->db->last_query(); exit; and run the code. This will display the sql. Run this sql on your database and decide if the sql query that you are using is correct.

thanks ! i find my error ! thanks for your help !

Theme © iAndrew 2016 - Forum software by © MyBB