dongyou7292 2017-06-21 14:55
浏览 43

在codeigniter中匹配后自动完成擦除不起作用

i am using autocomplete to my project and it is working fine with displaying record like image below.

enter image description here

but when i enter more letter to textbox result remaining the same like image below.

enter image description here

so how can i remove it and result should display matched data.my view file is

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-autocomplete/1.0.7/jquery.auto-complete.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<!-- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script> -->
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/jquery-ui.min.js"></script>
<input class="form-control ui-autocomplete-input" name="src" id="src" type="text" value="<?if (!empty($rule_info['src'])) {echo $rule_info['src'];} else{ echo 'any';}?>" pattern="[a-zA-Z0-9_.:]+" placeholder="Source Address" <?if (!empty($rule_info['src'])) {} else{ echo 'disabled';}?> autocomplete="off">
$(function() {
    $( "#dst" ).autocomplete({ //the recipient text field with id #username
        source: function( request, response ) {
            $.ajax({
                url: "<?php echo base_url();?>rule/search_alias_for_rule",
                dataType: "json",
                data: request,
                error: function(xhr, status, error) {
                  var err = eval("(" + xhr.responseText + ")");
                  alert(err.Message);
                },
                success: function(data){
                    if(data.response == 'true') {
                       response(data.message);
                    }
                }
            });
        }
    });
});

and then controller functio is.

 public function search_alias_for_rule(){

    $username = trim($this->input->get('term', TRUE)); //get term parameter sent via text field. Not sure how secure get() is

    $this->db->select('name');
    $this->db->from('alias');
    $this->db->like('name', $username);
    $this->db->limit('5');
    $query = $this->db->get();

    if ($query->num_rows() > 0)
    {
        $data['response'] = 'true'; //If username exists set true
        $data['message'] = array();

        foreach ($query->result() as $row)
        {
            $data['message'][] = array(
                'label' => $row->name,
                'value' => $row->name
            );
        }
    }
    else
    {
        $data['response'] = 'false'; //Set false if user not valid
    }

    echo json_encode($data);
}

how can i do that? please help me.

  • 写回答

3条回答 默认 最新

  • dtcpvz8162 2017-06-21 15:19
    关注

    Try with set the type of method in $.ajax function and your data:

    $(function() {
        $( "#dst" ).autocomplete({ //the recipient text field with id #username
            source: function( request, response ) {
                $.ajax({
                    type: 'GET',
                    data: {
                        term: request.term
                    },
                    url: "<?php echo base_url();?>rule/search_alias_for_rule",
                    dataType: "json",
                    error: function(xhr, status, error) {
                      var err = eval("(" + xhr.responseText + ")");
                      alert(err.Message);
                    },
                    success: function(data){
                        if(data.response == 'true') {
                           response(data.message);
                        }
                    }
                });
            }
        });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c