dtslobe4694 2015-01-15 08:08
浏览 17
已采纳

基于类别动态自动完成

i have a problem when i am trying to create a autocomplete with dynamic value that based on combobox using codeigniter, i have tried using ajax and no success.

here is my ajax code for calling item in category

<script type="text/javascript">
$(document).ready(function() {  
    $("#jenis").change(function(){              
        $.ajax({
            type : "POST",
            url: "<?php echo base_url(); ?>whz/admin/get_item",
            dataType: "html",
            data : "item=" + $("#jenis").val(),
            success: function(data)
            { 
                $("#showitem").text(data);  
            }
        });
    });
});
</script>

this is my autocomplete jquery code

<div id="showitem">
    <script>
     $(function() {
        var availableTags = [
        <?php foreach ($item as $row){
                echo '"'.$row->item_name.'",';}?>
        ];
        $( "#autotags" ).autocomplete({
        source: availableTags
        });
     });
    </script>
</div>

and here is my controller

public function get_item()
    {
        $this->load->model('whz_model');
        $category = $this->input->post('item');
        $item=$this->whz_model->get_item_by_cat($category);
        $script = '
          $(function() {
            var availableTags = [';
            foreach ($item as $row)
            {
                $script .= '"'.$row->item_name.'",';
            }

        $script .= '];
            $( "#autotags" ).autocomplete({
              source: availableTags
            });
          });';

        echo $script;
    }

i am considering using json as another option, but i still don't have enough experience using it.

sorry for bad english, thanks for your help

  • 写回答

2条回答 默认 最新

  • douduo2407 2015-02-13 06:40
    关注

    i already fix it with another method i found in the internet, it might be not the best but it works with me, here is the link

    http://www.danielrosca.ro/blog/en/codeigniter-autocomplete/

    thank you for all of your answer

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题