如何将复选框附加到我的Ajax响应中 [英] How can i append checkboxes to my ajax response
本文介绍了如何将复选框附加到我的Ajax响应中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为从数据库接收的数据动态创建复选框.
I am trying to create checkboxes dynamically for the data received from database.
jQuery和AJAX调用:
jQuery and AJAX call:
$("#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" />
当我保持警惕时收到回复:
Response received when I kept alert:
[ "abc", "def"]
请提供您宝贵的建议.作为AJAX和jQuery的新手,我很难获得这个结果.
Kindly provide your valuable suggestions. Being new to AJAX and jQuery I am facing a tough time in getting this result.
推荐答案
您可以尝试这样的事情
success: function(data) {
$("#resultDiv").html("");
$.each(data, function(i, record) {
$("#resultDiv").append("<input type='checkbox' id='chk-" + i + "' name='" + record + "' /> " + record);
});
}
这篇关于如何将复选框附加到我的Ajax响应中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文