Ajax对下拉列表自动完成和响应的响应就像这样
{“consignmentList”:[“”,“AAA”,“ABC”,“BHU”,“MAN”,“WER”,“ZXC”]}
现在我想获取所有if if循环并以列表格式显示在ul字段中。
function autocomplet() {
var min_length = 0; // min caracters to display the autocomplete
var consignmentID = $('#consignmentID').val();
var consignmentList = $('#consignmentList');
if (consignmentID.length >= min_length) {
$.ajax({
url: '/jqueryreturn',
type: 'POST',
datatype: JSON,
data: {
consignmentID: consignmentID
},
success: function(data) {
consignmentList.show();
consignmentList.html(data);
}
});
} else {
$('#consignmentList').hide();
}
}
// set_item : this function will be executed when we select an item
function set_item(item) {
// change input value
$('#consignmentID').val(item);
// hide proposition list
$('#consignmentList').hide();
}
<div>
<label style="margin:15px 0 0 0;">Consignment:</label>
<input onkeyup="autocomplet()" id="consignmentID" type="text" class="inputlt" name="consignmentId" value="${(consign._id)!" "}" id="c" style="font-size: 16px " onclick="clearInput(this)">
<ul id="consignmentList"></ul>