Jquery在codeigniter中自动完成检索值但不显示它们 [英] Jquery autocomplete in codeigniter retrieving values but not displaying them

查看:61
本文介绍了Jquery在codeigniter中自动完成检索值但不显示它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过几个小时的解密教程后,我终于得到了codeigniter和jquery自动完成功能,可以互相合作......有点儿。

After a few hours of deciphering tutorials, I finally got codeigniter and jquery autocomplete to work with each other...kind of.

Firebug正在显示正确的搜索结果术语以JSON格式返回,但下拉框未显示任何文本。如果有2个结果,它会显示2个空行。

Firebug is displaying the correct search terms back in JSON format, but the drop down box is not displaying any text. If there are 2 results, it displays 2 empty rows.

你可以在这里看到它不工作: http://rickymason.net/blurb/main/home

you can see it 'not working' here: http://rickymason.net/blurb/main/home

JS:

$(document).ready(function() {
    $(function(){
        $( "#filter" ).autocomplete({
            source: function(request, response) {
                $.ajax({
                url: "http://rickymason.net/blurb/main/search/",
                data: { term: $("#filter").val()},
                dataType: "json",
                type: "POST",
                success: function(data){
                    response(data);
                }
            });
        },
        minLength: 2
        });
    });
});

控制器:

    public function search()
    {
        $term = $this->input->post('term', TRUE);
        $this->thread_model->autocomplete($term);
    }

型号:

    public function autocomplete($term)
    {
        $query = $this->db->query("SELECT tag
            FROM filter_thread ft
            INNER JOIN filter f
            ON ft.filter_id = f.filter_id
            WHERE f.tag LIKE '%".$term."%'
            GROUP BY tag");
        echo json_encode($query->result_array());
    }

希望它很容易解决!

谢谢

推荐答案

将代码更改为类似的东西(我已在您的网站上测试过)

Changing your code to something like this would work(I have tested in your site)

$( "#filter" ).autocomplete({
        source: function(request, response) {
            $.ajax({
            url: "http://rickymason.net/blurb/main/search/",
            data: { term: $("#filter").val()},
            dataType: "json",
            type: "POST",
            success: function(data){
               var resp = $.map(data,function(obj){
                    return obj.tag;
               }); 

               response(resp);
            }
        });
    },
    minLength: 2
});

将上述代码块复制并粘贴到firebug控制台中,然后尝试自动完成。它会工作。我尝试在你的网站上运行。

Copy and paste the above code block in your firebug console and then try the autocomplete. It will work. I tried in your site and it worked.

其次你不需要 $(文件).ready(function(){ $(function(){同时完成同样的事情。

Secondly you dont need both $(document).ready(function() { and $(function(){ at the same time as they accomplish the same thing.

检查 jQuery UI自动填充的这一部分


预期数据格式

Expected data format

来自本地数据,网址或回调的数据有两种变体:

The data from local data, a url or a callback can come in two variants:

字符串数组:

[Choice1,Choice2]

[ "Choice1", "Choice2" ]

标签和值属性的对象数组:[{label:Choice1,value:value1},

label and value properties: [ { label: "Choice1", value: "value1" },

...]

参考: $。map

这篇关于Jquery在codeigniter中自动完成检索值但不显示它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆