Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
    
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. –  Jhonatascf 13 hours ago

1 Answer 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']);

    }
}
share|improve this answer
    
now java function with no problem but the code isnt correct, I get No search results. in the text boxe always –  riccardo airone 7 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.