0

i have some problem with the basicly function of jquery autocomplete in codeigniter but i think that the error isnt jquery

the code:

the view:

<link rel="stylesheet" href="<?php echo base_url();>application/libraries/jquery-ui.css" type="text/css">

<script type="text/javascript" src="<?php echo base_url(); ?>application/libraries/jquery-1.10.2.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>application/libraries/jquery-ui.js"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            $('#client_name').autocomplete({
                source: "<?php echo site_url('site/check_in_client/?'); ?>"
            });
        });
    </script>
    <input type="text" name="client_name" id="client_name" placeholder="nome"/>

the model:

function check_in_client($name) {
   $this->db->like('name',$name, 'both');
   $query = $this->db->get('client');
   return $query->result();    
}

the controller:

function check_in_client() {
    $this->load->library('javascript');
    $this->load->view('check_in_client');
    if(isset($_GET['term'])) {
        $result= $this->membership_model->check_in_client($_GET['term']);
        if(count($result) > 0) {
            foreach($result as $pr) 
                $arr_result[] = $pr->name;
            echo json_encode($arr_result);
        }
    }
}

the code load a view with a blank text boxe where is the problem?

thanks a lot by

1
  • Did you tested if the "$_GET" variable is set with any value? You can try $this->input->get_post(). This is a CI's native method. Commented Mar 25, 2015 at 16:58

1 Answer 1

1

In your view file:

    <link rel="stylesheet"href="//code.jquery.com/ui/1.11.4/themes/smoothness/jqueryui.css">
      <script src="//code.jquery.com/jquery-1.10.2.js"></script>
      <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
      <link rel="stylesheet" href="/resources/demos/style.css">
 <script type="text/javascript">
        $(document).ready(function() {
            $('#client_name').autocomplete({
                source: "<?php echo site_url('site/check_in_client/?'); ?>"
            });
        });
    </script>
    <input type="text" name="client_name" id="client_name" placeholder="nome"/>

In your Model:

 function check_in_client($name) {
       $this->db->select('name',false);
       $this->db->like('name',$name, 'both');
       $query = $this->db->get('client');
      if ($query->num_rows > 0) {
            foreach ($query->result() as $row) {
                $datas[] = $row->name;
            }

            echo json_encode($datas);
        } else {
            $datas[] = 'Oops! No suggestions found. Try a different search.';
            echo json_encode($datas);
        } 
    }

In your Controller:

function check_in_client() {
    $this->load->library('javascript');
    $this->load->view('check_in_client');
    if(isset($_GET['term'])) {
        $result= $this->membership_model->check_in_client($_GET['term']);

    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

now java function with no problem but the code isnt correct, I get No search results. in the text boxe always
Worked perfectly, even solved my problem of encoding. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.