朋友们,我有几个问题需要找到一个好的教程/如何基于代码点火器和jquery函数"自动完成"
在我的程序中,我有会话
我发布了一些代码
控制器:
function __construct()
{
parent::__construct();
$this->is_logged_in();
}
function check_in_client() {
$this->load->model('membership_model');
$this->load->library('javascript');
$this->load->view('check_in_cliente');
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);
}
}
型号:
function check_in_client($name) {
$this->db->like('nome',$name, 'both');
return $this->db->get('clienti')->result();
}
视图:
<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" />
浏览器中的结果是当我在输入栏中放一些东西时,结果是
没有搜索结果
有人帮我吗?
非常感谢向致以最良好的问候
将$_GET['term']
更改为$_REQUEST['term']
function check_in_client() {
$this->load->model('membership_model');
$this->load->library('javascript');
$this->load->view('check_in_cliente');
if(isset($_REQUEST['term'])) {
$result= $this->membership_model->check_in_client($_REQUEST['term']);
if(count($result) > 0) {
foreach($result as $pr)
$arr_result[] = $pr->name;
echo json_encode($arr_result);
}
}
希望这个能帮助你!
将$_GET['term']
更改为$this->input->get('term', TRUE)
function check_in_client() {
$this->load->model('membership_model');
$this->load->library('javascript');
$this->load->view('check_in_cliente');
if(isset($this->input->get('term', TRUE)) {
$result= $this->membership_model->check_in_client($this->input->get('term', TRUE));
if(count($result) > 0) {
foreach($result as $pr)
$arr_result[] = $pr->name;
echo json_encode($arr_result);
}
}