我在codeigniter中的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);
}
}
}
代码加载带有空白文本框的视图 问题出在哪里?
非常感谢
答案 0 :(得分: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']);
}
}