后台
/** * 获取所有角色 * @return */ @RequestMapping("getAllRole") @ResponseBody public ListgetAllRole(){ List result = roleService.getAllRole(); return result; }
前端JS
function loadRoleChk(url,tag_id){ $.ajax({ url:url, dataType:'json', data:{}, type:'post', success:function(data){ var options=""; //字符串拼接 for(var i in data){ //遍历json数组 options += ""+data[i].rolename+" " } $('#'+tag_id).empty(); $('#'+tag_id).html(options); }, error:function(){} });}
调用
$(function(){ loadRoleChk("/${appName}/manager/roleController/getAllRole","roleAccess"); });
HTML