当前位置: 移动技术网 > IT编程>脚本编程>Ajax > 添加后台list给前台select标签赋值简单实现

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

2017年12月12日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:

$.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);
}
}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网