如何在表单中选择多个值:使用ajax响应选择
我有一个Ajax调用,它将返回一个属性为collection of profile的对象。如何使用这些配置文件集合在如何在表单中选择多个值:使用ajax响应选择,ajax,jsp,Ajax,Jsp,我有一个Ajax调用,它将返回一个属性为collection of profile的对象。如何使用这些配置文件集合在中选择多个值 $.ajax({ ... // some omitted codes // ... success : function(response) { response.profiles // collection of profiles } <form:select id="profile
中选择多个值
$.ajax({
... // some omitted codes // ...
success : function(response) {
response.profiles // collection of profiles
}
<form:select id="profile" path="profiles"
items="${profilelist}" multiple="true" itemValue="id" itemLabel="type"/>
$.ajax({
…//一些省略的代码//。。。
成功:功能(响应){
response.profiles//配置文件集合
}
这似乎是一个重复的问题,请始终首先尝试查看您的问题是否存在类似的问题
您还没有指定您正在使用的框架,因为若您正在使用任何框架,那个么您可以基于该框架在选项中获取数据
这里我要回答的是没有任何框架
<form:select id="profile" path="profiles"
items="${profilelist}" multiple="true" itemValue="id" itemLabel="type"/>
ajax调用应该是这样的
$.ajax({
type: "GET",
url: "http://.......api/1/AbsenceType",
dataType: "json",
success: function (data) {
// Get select
var select = document.getElementById('profiles');
// Add options
for (var i in data) {
$(select).append('<option value=' + data[i] + '>' + data[i] +
'</option>');
// Set selected value
$(select).val(data[1]);
}
}
$.ajax({
键入:“获取”,
url:“http://.......api/1/AbsenceType",
数据类型:“json”,
成功:功能(数据){
//选择
var select=document.getElementById('profiles');
//添加选项
用于(数据中的var i){
$(选择).append(“”+数据[i]+
'');
//设置选定值
$(选择).val(数据[1]);
}
}
希望这有帮助