V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
ArthurMarcel
V2EX  ›  问与答

JQuery-UI 里的 Autocomplete 怎么处理获取到的数据?

  •  
  •   ArthurMarcel · 2017-05-14 17:35:48 +08:00 · 2450 次点击
    这是一个创建于 2510 天前的主题,其中的信息可能已经有所发展或是发生改变。

    antocomplete 实现代码:

    $( "#que_title" ).autocomplete ({

        delay:500,
        max:10,
        minChars:1,
        width:400,
        scrollHeight:5,
        matchContains:true,
        autoFill:true,
        minLength: 2,
        source: function(request,response){
            $.ajax({
                Type:"post",
                url:"/QuestionAction?method=Question_title",
                dateType:"json",
                data:{
                    question_title:request.term
                },
                success:function (data) {
                    response($.map(data,function (item) {
                       return{
                        label:item.qtitle,
                        value:item.qtitle
                       };
                    }));
                },
                error:function () {
                    alert("异常");
                }
            });
        },
        select: function (event, ui) {
            //提交搜索
        }
    
    });
    

    处理请求的 servlet:

    public void Question_title(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException

    {

        String qtitle = req.getParameter("question_title");
        List<Question> questions = qbiz.selectAllQuestion(qtitle);
        System.out.println(questions);
        String json = JSON.toJSONString(questions,true);
        res.getWriter().print(json);
    

    }

    直接贴代码是不是不符合规定。 读了一遍 demo,本地的数据源可以实现,可是 console 没有打印出从数据库查询后的数据。检查查询方法没有问题。迷茫了,求聚聚...

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   957 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 20:41 · PVG 04:41 · LAX 13:41 · JFK 16:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.