2015-03-25 95 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