页面
<div class="manage-Car-add-info-sn">
<p style="25%; height:70%;float:left;text-align:right">设备SN编号:</p>
<form:input path="sn" id="sn" list="suggest_ul" class = "input_SN" type="text" />
<datalist id="suggest_ul"></datalist>
ajax
$("#sn").keyup(function(){
//如果文本框为空,不发送请求
if($("#sn").val().length == 0){
$("#suggest_ul").hide(0);
return false;
}
console.log($("#sn").val());
var url = "getDeviceSn";
var sn = $("#sn").val();
$.ajax({
type:"post",
url :url,
data: {"sn":sn},
datatype:"json",
success:function(json){
if(json){
$("#suggest_ul").show(0);
$("#suggest_ul").html(json);
}
}
})
})
controller
List<String> modelList = sectorService.getDeviceSn(sn);
StringBuffer sb = new StringBuffer();
for (String string : modelList) {
sb.append("<option>" + string + "</option>");
}
return sb.toString();