从数据库动态添加数据到下拉框(select)中

在controller中:

@RequestMapping("/type")
public String getType(HttpServletRequest req, HttpServletResponse rsp)
throws IOException {
req.setCharacterEncoding("utf-8");
rsp.setCharacterEncoding("utf-8");
System.out.println("进入gettype......");
List listType = libraryService.getBookType();
PrintWriter out=rsp.getWriter();
out.print(JSON.toJSONString(listType));
return null;
}

页面上:



js函数:

function cc(){
 $.post("<%=path%>/home/type", {} , function(data){

var res = $.parseJSON(data);
$("#sel_menu3").html("");
$.each(res, function(i, n) {
$("#sel_menu3").append(
"");
});

你可能感兴趣的:(Java开发)