我喜欢在我的网站上有自动完成搜索功能。网站上有一个带有搜索过滤器的页面。当用户登陆此页面时,所有用户的记录都以表格格式显示在该页面上。有一个输入框可以过滤掉结果。例如,如果我键入 player,表格可能如下所示。
身份证播放器
1 名玩家获胜
2 玩家获胜
3 玩家获胜
请告诉我该怎么做?这是我的代码目前的样子...
视图:
<html>
<title></title>
<head>
<!-- Jquery Packages -->
<link type="text/css" rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css "/>
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<!-- Jquery Package End -->
<script type="text/javascript">
$('#txtinput').autocomplete({
source: source: "<?php echo site_url('record/index/?'); ?>"
});
</script>
</head>
<body>
<!-- Your Input Text Box-->
<input type="text" id="txtinput" size="20" />
</body>
</html>
控制器:
public function index(){
$this->load->helper('url');
$this->load->helper('html');
$this->load->library('javascript');
$this->load->library('javascript/Jquery');
$this->load->view('record_view');
$this->load->model('record_model');
if (isset($_GET['term'])){
$result = $this->record_model->getData($_GET['term']);
if (count($result) > 0){
foreach ($result as $key ) {
$abc[] = $key->result;
}
echo json_encode($abc);
}
}
}
型:
public function getData($result)
{
$this->db->like('result', $result, 'both' );
return $this->db->get('history')->result();
}
$('#txtinput').autocomplete({
source: **"source:"** "<?php echo site_url('record/index/?'); ?>"
});
删除额外的来源..
并把$this->加载>视图('record_view');在获取控制器的其他内容中