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 没有打印出从数据库查询后的数据。检查查询方法没有问题。迷茫了,求聚聚...