CodeIgniter Forums
result from autocomplete with ajax jquery json is not exactly - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: result from autocomplete with ajax jquery json is not exactly (/showthread.php?tid=53269)



result from autocomplete with ajax jquery json is not exactly - El Forum - 07-17-2012

[eluser]misakitran[/eluser]
I use autocomplete jquery-ui. Results responsed but not exactly.

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

Code:
//-------------------- 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);
    }

Code:
//-------------------- Model
function get_auto_complete($code)
    {
        $this->db->select('code');
        $this->db->from('products');      
        $this->db->like('code',$code,'after');
        $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 !


result from autocomplete with ajax jquery json is not exactly - El Forum - 07-18-2012

[eluser]john_j[/eluser]
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.


result from autocomplete with ajax jquery json is not exactly - El Forum - 07-26-2012

[eluser]misakitran[/eluser]
thanks ! i find my error ! thanks for your help !