我正在尝试在我的网站上使用http://jqueryui.com/autocomplete/#multiple-remote,但我无法让它给出正确的结果。
我的 HTML 是:
<input id="movies-text" size="50" />
我的 Jquery 代码是:
$('#movies-text').autocomplete({
minLength:3,
source:function(request,response){
$.getJSON('searchmovies.jsp',{q:request.term},function(result){
response($.map(result,function(item){
return item.value;
}));
});
}
});
searchmovies.jsp 看起来像这样:
<%@ page contentType="application/json" language="java" import="java.sql.*" errorPage="" %>
<%
response.setContentType("application/json");
response.setHeader("Content-Disposition", "inline");
%>
[
{"value":"Pulp fiction"},
{"value":"The hobbit"},
{"value":"Apocalypse Now"},
{"value":"As good as it gets"},
{"value":"Annie hall"},
{"value":"Butch Cassidy and the sundance kid"},
{"value":"Terminator"}
]
无论我输入什么,它都会给出下拉列表中的所有值。