0
我最近把手放在CI上,仍在學習。無法從數據庫獲取CI自動完成功能
我的控制器:
public function test() {
$keyword=$this->input->post('search[1]');
$data=$this->hbc_model->search_autocomplete($keyword);
//echo json_encode($data);
$this->load->view('headfoot/test-header-main');
$this->load->view('test');
$this->load->view('headfoot/test-footer-main');
}
型號:
function search_autocomplete($search_term){
$this->db->select('v_city_name');
$this->db->like('v_city_name', $search_term);
$response = $this->db->get('vbc_city')->result_array();
// var_dump($response);
return $response;
}
,並查看:
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#main-search").autocomplete({
source: 'hbc_Model/search_autocomplete'
});
});
</script>
</head>
<body>
<input type="text" id="main-search" name="search[1]" size="20" />
</body>
當我取消從模型或控制器甚至回聲JSON響應vardump,它顯示城市在數據庫的全部頁面上命名,但在用作自動完成時不起作用。
任何幫助,將不勝感激。
的'.autocomplete()'函數是jQueryUI的一部分,所以我加了這些標籤你的問題。您的問題可能是JavaScript,因此您必須在瀏覽器控制檯中查找錯誤。 – Sparky