dhtmlxtree学习笔记三(ajax动态获取数据)
?
server端代码
@RequestMapping(value="/ajaxTree")public void ajaxTree(HttpServletRequest request,HttpServletResponse response){String id = request.getParameter("id");System.out.println(id);PrintWriter pw = null;try {pw = response.getWriter();//{'parent':'parentid','id':'selfid','item':'itemname'}pw.write("{'parent':'"+id+"','id':'selfid','item':'itemname'}");pw.flush();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{if(pw != null){pw.close();}}}
?
备注:server端返回的是一个json格式的字符串,将这个字符串输出到前端,然后再将其转换为JSON对象,最后作为数据展示到前端,如果是多条数据,则通过json数组传递
?