2015-03-25 91 views
0

我有一些问题,在笨jquery的自动完成的basicly功能,但我认为错误的心不是jQuery的笨和jQuery自动完成

代码:

的观点:

<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"/> 

模型:

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

控制器:

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); 
     } 
    } 
} 

代码负载与空白文本boxe 哪里的问题的视图?

非常感谢由

+0

难道你如果测试“$ _GET”变量是否设置了任何值? 你可以试试$ this-> input-> get_post()。这是一个CI的本地方法。 – Jhonatascf 2015-03-25 16:58:28

回答

1

在您的视图文件:

<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"/> 

在你的模型:

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); 
     } 
    } 

在你的控制器:

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

    } 
} 
+0

现在的java函数没有问题,但代码不正确,我得到没有搜索结果。在文本框中总是 – 2015-03-25 22:54:33

+0

完美工作,甚至解决了我的编码问题。谢谢。 – slellis 2017-07-11 13:49:59