我正在尝试使用 Solr 和 JQuery UI 实现 HTML 自动完成表单。
Solr 的服务器记录查询并且 Firebug 确认我得到了一个 json 数组:
{"responseHeader":{"status":0,"QTime":3,"params":{"fl":"defaultCommonNameString","q":"defaultCommonName:angle","wt":"json"}},"response":{"numFound":42,"start":0,"docs":[{"defaultCommonNameString":["angle"]},{"defaultCommonNameString":["reporter un angle"]},{"defaultCommonNameString":["formule pour un angle"]},{"defaultCommonNameString":["angle droit"]},{"defaultCommonNameString":["angle au centre"]}, ...]}}}
但此代码不显示响应:
<link rel="stylesheet" type="text/css" href="css/demos.css" />
<script type="text/javascript" src="jquery/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="jquery/jquery.ui.core.js"></script>
<script type="text/javascript" src="jquery/jquery.ui.widget.js"></script>
<script type="text/javascript" src="jquery/jquery.ui.position.js"></script>
<script type="text/javascript" src="jquery/jquery.ui.autocomplete.js"></script>
<script>
$(function() {
$("#autosearch").autocomplete({
source: function( request, response ) {
$.ajax({
url: "http://localhost:8080/solr/select",
data: {
q: "defaultCommonName:"+request.term,
wt:"json",
fl: "defaultCommonNameString",
},
dataType: "json",
type: "GET",
success: function( data ) {
data=parse();
function parse(){
var parsedQueries=[];
for(var i=0;i<data.response.docs.length;i++){
parsedQueries[i]=data.response.docs[i].Query;
}
return parsedQueries;
}
response($.map(data.response.docs, function( item ) {
return {
label: item,
value: item
};
}));
}
});
},
minLength: 1
});
});
</SCRIPT>
</head>
<body>
<label for="autosearch">Search Here : </label>
<input id="autosearch"/>
</body>
感谢帮助