我正在尝试为从数据库接收的数据动态创建复选框。
jQuery和AJAX调用:
$("#destinationName").autocomplete({
source : function(request, response) {
$.ajax({
url: "${pageContext.request.contextPath}/showDestinations",
type: "POST",
data : { term : request.term },
dataType : "json",
success : function(data) {
alert(data);
}
});
}
});
<label>Destination</label>
<input type="text" id="destinationName" name="destinationName" value="${Form.destinationName}" class="field" />
当我保持警惕时收到回复:
[ "abc", "def"]
请提供您宝贵的建议。作为AJAX和jQuery的新手,我很难获得这个结果。
您可以尝试这样的事情
success: function(data) {
$("#resultDiv").html("");
$.each(data, function(i, record) {
$("#resultDiv").append("<input type='checkbox' id='chk-" + i + "' name='" + record + "' /> " + record);
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句