首页 > 语言 > JavaScript > 正文

添加后台list给前台select标签赋值简单实现

2024-05-06 15:49:17
字体:
来源:转载
供稿:网友
本文为大家介绍下通过添加后台list怎么实现给前台select标签赋值,具体代码如下,感兴趣的朋友可以参考下哈

复制代码 代码如下:


$.ajax({
url : "user!findUserList.action",
type : "post",
success: function(data){
var jsonObj=eval("("+data+")");
$.each(jsonObj, function (i, item) {
jQuery("#userList").append("<option value="+ item.userId+">"+ item.userRealName+"</option>");
});
},
error: function(text) {}
});


复制代码 代码如下:


public void findUserList() throws IOException {
List<UserModel> roleuserList = userService.findUserList();
String json = JSONArray.fromObject(roleuserList).toString();
writeHtml(json);;
}


复制代码 代码如下:


protected void writeHtml(String strData) {
try {
response.setContentType("text/html; charset=UTF-8");
PrintWriter pw = response.getWriter();
pw.write(strData);
pw.flush();
pw.close();
} catch (IOException e) {
log.error("writeHtml()", e);
}
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选