Javascript 在Codeigniter中自动完成多个值

Javascript 在Codeigniter中自动完成多个值,javascript,php,jquery,json,codeigniter,Javascript,Php,Jquery,Json,Codeigniter,我对CodeIgniter和Jquery中的自动完成有问题 我有一个控制器 <?php public function search() { $user = $_GET['term']; $query = $this ->db ->select('nama_kota') ->like('nama_kota', $user) ->get('kota');

我对CodeIgniter和Jquery中的自动完成有问题 我有一个控制器

<?php
public function search() {
    $user = $_GET['term'];
    $query = $this
            ->db
            ->select('nama_kota')
            ->like('nama_kota', $user)
            ->get('kota');
    if ($query->num_rows() > 0) {
        foreach ($query->result_array() as $row) {
            $row_set[] = htmlentities(stripslashes($row['nama_kota']));
        }
        echo json_encode($row_set);
    }
}
?>

我有一个观点

<script>
    $(function () {
        var availableTags = "<?php echo base_url('admin/kota/search'); ?>";
        $("#user-input").autocomplete({
            source: availableTags
        });
    });
</script> 
<input id="user-input" type="text" name="nama_kota" placeholder="Search User" autocomplete="on">

$(函数(){
var availableTags=“”;
$(“#用户输入”)。自动完成({
资料来源:availableTags
});
});
一切都好吗 但我尝试了多种价值观

<script>
    $(function () {
        var availableTags = "<?php echo base_url('admin/kota/search'); ?>";
        function split(val) {
            return val.split(/,\s*/);
        }
        function extractLast(term) {
            return split(term).pop();
        }
        $("#user-input").autocomplete({
            minLength: 0,
            source: function (request, response) {
                // delegate back to autocomplete, but extract the last term
                response($.ui.autocomplete.filter(
                        availableTags, extractLast(request.term)));
            },
            focus: function () {
                // prevent value inserted on focus
                return false;
            },
            select: function (event, ui) {
                var terms = split(this.value);
                // remove the current input
                terms.pop();
                // add the selected item
                terms.push(ui.item.value);
                // add placeholder to get the comma-and-space at the end
                terms.push("");
                this.value = terms.join(", ");
                return false;
            }
        });
    });
</script> 
<input id="user-input" type="text" name="nama_kota" placeholder="Search User" autocomplete="on">

$(函数(){
var availableTags=“”;
功能拆分(val){
返回val.split(/,\s*/);
}
功能提取最后(学期){
返回拆分(term.pop();
}
$(“#用户输入”)。自动完成({
最小长度:0,
来源:功能(请求、响应){
//委托回自动完成,但提取最后一项
响应($.ui.autocomplete.filter(
availableTags,extractLast(request.term));
},
焦点:功能(){
//防止在焦点上插入值
返回false;
},
选择:功能(事件、用户界面){
var术语=分割(该值);
//删除当前输入
terms.pop();
//添加所选项目
术语推送(ui.item.value);
//添加占位符以在末尾获得逗号和空格
术语。推送(“”);
this.value=terms.join(“,”);
返回false;
}
});
});
无工作和可用标记仅读取地址url控制器中无函数
有什么不对劲的家伙请帮帮我,谢谢如果你需要这样的输出,你需要哪种类型的输出

例如。 名称 地址:, 血型


使用自动完成调用的输出

如果需要这样的输出,您需要哪种类型的输出

例如。 名称 地址:, 血型


由于自动完成呼叫的输出

很抱歉,我的工作很忙 这是对控制器的JS调用

<script>

    jQuery("#h_student_name").autocomplete({
        minLength: 0,
        source: "DropdownController/hostel_students/" + $("#h_student_name").val(),
        autoFocus: true,
        scroll: true,
        dataType: 'jsonp',
        select: function (event, ui) {
            jQuery("#h_student_name").val(ui.item.contactPerson);
            jQuery("#h_student_id").val(ui.item.code);
        }
    }).focus(function () {
        jQuery(this).autocomplete("search", "");
    });
</script>

jQuery(“#h#u学生名”).autocomplete({
最小长度:0,
来源:“DropdownController/hotel_student/”+$(“#h_student_name”).val(),
自动对焦:对,
卷轴:没错,
数据类型:“jsonp”,
选择:功能(事件、用户界面){
jQuery(“#h#u学生名”).val(ui.item.contactPerson);
jQuery(“#h#u student_id”).val(ui.item.code);
}
}).focus(函数(){
jQuery(this.autocomplete(“搜索”);
});
这是呼叫控制器

<?php
//Hostel Student Auto compelete
public function hostel_students(){


    $term = trim(strip_tags($this->input->get('term')));
    if( $term == ''){
        $like = $term;
        $result_set = $this->DropdownModel->hostel_students(array('hostel_status_id' => 1));
        $labels = array();
        foreach ($result_set as $row_set) {
            $labels[] = array(
                'label' => $row_set->student_name.' S/D '.$row_set->father_name.' ,Form# '.$row_set->form_no.' ',
                'code' => $row_set->hostel_id,
                'value' => $row_set->student_name,
            );
        }
        $matches = array();
        foreach($labels as $label){
            $label['value'] = $label['value'];
            $label['code'] = $label['code'];
            $label['label'] = $label['label'];

            $matches[] = $label;
        }
        $matches = array_slice($matches, 0, 10);
        echo json_encode($matches);
    } else if($term != ''){
        $like = $term;
        $result_set = $this->DropdownModel->hostel_students(array('hostel_status_id' => 1), $like);
        $labels = array();
        foreach ($result_set as $row_set) {
            $labels[] = array(
                'label' => $row_set->student_name.' S/D '.$row_set->father_name.' ,Form# '.$row_set->form_no.' ',
                'code' => $row_set->hostel_id,
                'value' => $row_set->student_name,
            );
        }
        $matches = array();
        foreach($labels as $label){
            $label['value'] = $label['value'];
            $label['code'] = $label['code'];
            $label['label'] = $label['label'];

            $matches[] = $label;
        }
        $matches = array_slice($matches, 0, 10);
        echo json_encode($matches);
    }
}
?>
<?php
// Hostel student autocomplete    
public function hostel_students($where, $like = NULL){
    if($like):
        $this->db->like('student_name', $like);
        $this->db->or_like('form_no', $like);
        $this->db->or_like('college_no', $like);
    endif;
        $this->db->join('student_record', 'student_record.student_id=hostel_student_record.student_id');
        return $this->db->where($where)->get('hostel_student_record')->result();
    }
}
?>

这是通话模式

<?php
//Hostel Student Auto compelete
public function hostel_students(){


    $term = trim(strip_tags($this->input->get('term')));
    if( $term == ''){
        $like = $term;
        $result_set = $this->DropdownModel->hostel_students(array('hostel_status_id' => 1));
        $labels = array();
        foreach ($result_set as $row_set) {
            $labels[] = array(
                'label' => $row_set->student_name.' S/D '.$row_set->father_name.' ,Form# '.$row_set->form_no.' ',
                'code' => $row_set->hostel_id,
                'value' => $row_set->student_name,
            );
        }
        $matches = array();
        foreach($labels as $label){
            $label['value'] = $label['value'];
            $label['code'] = $label['code'];
            $label['label'] = $label['label'];

            $matches[] = $label;
        }
        $matches = array_slice($matches, 0, 10);
        echo json_encode($matches);
    } else if($term != ''){
        $like = $term;
        $result_set = $this->DropdownModel->hostel_students(array('hostel_status_id' => 1), $like);
        $labels = array();
        foreach ($result_set as $row_set) {
            $labels[] = array(
                'label' => $row_set->student_name.' S/D '.$row_set->father_name.' ,Form# '.$row_set->form_no.' ',
                'code' => $row_set->hostel_id,
                'value' => $row_set->student_name,
            );
        }
        $matches = array();
        foreach($labels as $label){
            $label['value'] = $label['value'];
            $label['code'] = $label['code'];
            $label['label'] = $label['label'];

            $matches[] = $label;
        }
        $matches = array_slice($matches, 0, 10);
        echo json_encode($matches);
    }
}
?>
<?php
// Hostel student autocomplete    
public function hostel_students($where, $like = NULL){
    if($like):
        $this->db->like('student_name', $like);
        $this->db->or_like('form_no', $like);
        $this->db->or_like('college_no', $like);
    endif;
        $this->db->join('student_record', 'student_record.student_id=hostel_student_record.student_id');
        return $this->db->where($where)->get('hostel_student_record')->result();
    }
}
?>


有任何问题请评论我今天将在线

很抱歉,我的工作很忙 这是对控制器的JS调用

<script>

    jQuery("#h_student_name").autocomplete({
        minLength: 0,
        source: "DropdownController/hostel_students/" + $("#h_student_name").val(),
        autoFocus: true,
        scroll: true,
        dataType: 'jsonp',
        select: function (event, ui) {
            jQuery("#h_student_name").val(ui.item.contactPerson);
            jQuery("#h_student_id").val(ui.item.code);
        }
    }).focus(function () {
        jQuery(this).autocomplete("search", "");
    });
</script>

jQuery(“#h#u学生名”).autocomplete({
最小长度:0,
来源:“DropdownController/hotel_student/”+$(“#h_student_name”).val(),
自动对焦:对,
卷轴:没错,
数据类型:“jsonp”,
选择:功能(事件、用户界面){
jQuery(“#h#u学生名”).val(ui.item.contactPerson);
jQuery(“#h#u student_id”).val(ui.item.code);
}
}).focus(函数(){
jQuery(this.autocomplete(“搜索”);
});
这是呼叫控制器

<?php
//Hostel Student Auto compelete
public function hostel_students(){


    $term = trim(strip_tags($this->input->get('term')));
    if( $term == ''){
        $like = $term;
        $result_set = $this->DropdownModel->hostel_students(array('hostel_status_id' => 1));
        $labels = array();
        foreach ($result_set as $row_set) {
            $labels[] = array(
                'label' => $row_set->student_name.' S/D '.$row_set->father_name.' ,Form# '.$row_set->form_no.' ',
                'code' => $row_set->hostel_id,
                'value' => $row_set->student_name,
            );
        }
        $matches = array();
        foreach($labels as $label){
            $label['value'] = $label['value'];
            $label['code'] = $label['code'];
            $label['label'] = $label['label'];

            $matches[] = $label;
        }
        $matches = array_slice($matches, 0, 10);
        echo json_encode($matches);
    } else if($term != ''){
        $like = $term;
        $result_set = $this->DropdownModel->hostel_students(array('hostel_status_id' => 1), $like);
        $labels = array();
        foreach ($result_set as $row_set) {
            $labels[] = array(
                'label' => $row_set->student_name.' S/D '.$row_set->father_name.' ,Form# '.$row_set->form_no.' ',
                'code' => $row_set->hostel_id,
                'value' => $row_set->student_name,
            );
        }
        $matches = array();
        foreach($labels as $label){
            $label['value'] = $label['value'];
            $label['code'] = $label['code'];
            $label['label'] = $label['label'];

            $matches[] = $label;
        }
        $matches = array_slice($matches, 0, 10);
        echo json_encode($matches);
    }
}
?>
<?php
// Hostel student autocomplete    
public function hostel_students($where, $like = NULL){
    if($like):
        $this->db->like('student_name', $like);
        $this->db->or_like('form_no', $like);
        $this->db->or_like('college_no', $like);
    endif;
        $this->db->join('student_record', 'student_record.student_id=hostel_student_record.student_id');
        return $this->db->where($where)->get('hostel_student_record')->result();
    }
}
?>

这是通话模式

<?php
//Hostel Student Auto compelete
public function hostel_students(){


    $term = trim(strip_tags($this->input->get('term')));
    if( $term == ''){
        $like = $term;
        $result_set = $this->DropdownModel->hostel_students(array('hostel_status_id' => 1));
        $labels = array();
        foreach ($result_set as $row_set) {
            $labels[] = array(
                'label' => $row_set->student_name.' S/D '.$row_set->father_name.' ,Form# '.$row_set->form_no.' ',
                'code' => $row_set->hostel_id,
                'value' => $row_set->student_name,
            );
        }
        $matches = array();
        foreach($labels as $label){
            $label['value'] = $label['value'];
            $label['code'] = $label['code'];
            $label['label'] = $label['label'];

            $matches[] = $label;
        }
        $matches = array_slice($matches, 0, 10);
        echo json_encode($matches);
    } else if($term != ''){
        $like = $term;
        $result_set = $this->DropdownModel->hostel_students(array('hostel_status_id' => 1), $like);
        $labels = array();
        foreach ($result_set as $row_set) {
            $labels[] = array(
                'label' => $row_set->student_name.' S/D '.$row_set->father_name.' ,Form# '.$row_set->form_no.' ',
                'code' => $row_set->hostel_id,
                'value' => $row_set->student_name,
            );
        }
        $matches = array();
        foreach($labels as $label){
            $label['value'] = $label['value'];
            $label['code'] = $label['code'];
            $label['label'] = $label['label'];

            $matches[] = $label;
        }
        $matches = array_slice($matches, 0, 10);
        echo json_encode($matches);
    }
}
?>
<?php
// Hostel student autocomplete    
public function hostel_students($where, $like = NULL){
    if($like):
        $this->db->like('student_name', $like);
        $this->db->or_like('form_no', $like);
        $this->db->or_like('college_no', $like);
    endif;
        $this->db->join('student_record', 'student_record.student_id=hostel_student_record.student_id');
        return $this->db->where($where)->get('hostel_student_record')->result();
    }
}
?>


有任何问题请评论我,我今天将在线

添加代码而不是图像!!您想要什么样的示例输出?尝试回显$user=$\u GET['term'];在里面controller@AbdullaNilam代码createdAdd代码不是图像!!您想要什么样的示例输出?尝试回显$user=$\u GET['term'];在里面controller@AbdullaNilam代码创建我想显示kota tableonly name中的nama_kota或其他字段我想显示kota表中nama_kota字段中的记录请检查此url项目名称:admin controller:kota函数:Search如果admin是项目名称,则从您在基本url中已经给他的代码中删除我想要的显示kota tableonly name中的nama_kota或其他字段我想显示kota表中nama_kota字段中的记录请检查此url项目名称:管理员控制器:kota函数:搜索如果admin是项目名称,则从您在基本url中已经给他的代码中删除