Ztree 返回ajax json 数据

方法1:  

  @RequestMapping("/menu")

    public void getMenu(HttpServletRequest request,HttpServletResponse response) throws Exception{
    List<Menu> tree = menuService.getAllMenu();
    String json = JSONArray.toJSONString(tree);
  response.setCharacterEncoding("utf-8");
       response.getWriter().write(json);
       response.getWriter().close();

     }


 $(function (){
 $.ajax({
        type: "Post",
        url: "${rc.contextPath}/login/menu",
        dataType:"json",
        success: function (data) {
        $.fn.zTree.init($("#treeDemo"), setting, data);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert("树形结构加载失败!")
        }
    });
 });

猜你喜欢

转载自blog.csdn.net/tsapr/article/details/80485346