请查看您会理解的图像...此图像取自chrome开发工具,我正在控制台上打印JSON响应。
以下是自动完成代码。
$("#search-org").autocomplete({
width: 300,
max: 10,
delay: 100,
minLength: 1,
autoFocus: true,
cacheLength: 1,
scroll: true,
highlight: false,
source: function(request, response) {
$.ajax({
url : "../../SearchHelperController",
contentType : "application/json; charset=utf-8",
dataType : 'json',
type : 'GET',
cache : false,
data: {
searchKeyword: request.term,
searchType: $("#byName").val()
},
success: function(data, textStatus, jqXHR) {
console.log(data);
response(data);
},
error: function(jqXHR, textStatus, errorThrown){
console.log( textStatus);
}
});
},
select: function (event, ui) {
$("#org-id").val(ui.item.key);
},
});
html代码
<div class="radio">
<label><input type="radio" id="byName" name="byName" value="OU" checked> By Name</label>
<input type="text" id="org-id">
</div>
<div class="form-group">
<input type="text" class="form-control" id="search-org">
</div>
@AhmadBamieh,感谢您的支持,我解决了这个问题,这是代码,
HTML代码
<form action="#">
<table align="center" style="padding-top: 5%">
<tr>
<td align="right">AutoComplete:</td>
<td><input id="autoText" name="autoText" autofocus/></td>
<td align="right">Key:</td>
<td><input id="key" /></td>
</tr>
</table>
</form>
jQuery自动完成代码
$(document).ready(function() {
var value;
$("#autoText").autocomplete({
width: 300,
max: 10,
delay: 100,
minLength: 1,
autoFocus: true,
cacheLength: 1,
scroll: true,
highlight: false,
source: function(request, response) {
$.ajax({
url : "../AutoCompleteController",
contentType : "application/json; charset=utf-8",
dataType : 'json',
type : 'get',
cache : false,
data: {
term : request.term,
},
success: function(data) {
value = data;
response(data);
},
error: function(jqXHR, textStatus, errorThrown){
console.log( textStatus);
}
});
},
select: function (event, ui) {
lable = ui.item.value;
$.each(value, function(key, value){
if(lable == value) {
$("#key").val(key);
}
});
},
});
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句