Juery getJoson

备份数据:

 

function ajaxInfo(){
            $.getJSON("http://192.168.0.100:8080/JqueryAjax/ajax.do?id=10&jsoncallback=?",
                function(data){
                    $.each(data,function(i,item){    
                         alert("name="+item.name+"name1="+item.name1+"name2="+item.name2);
                      });
            });
         }

 

 

/**
     * Method execute
     *
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return ActionForward
     */
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
        try {
            String jsoncallback=request.getParameter("jsoncallback");
            PrintWriter out = response.getWriter();
           
            //out.println("<div style=\"background-color:#ffa; padding:20px\">"+request.getParameter("name")+"</div>");
           
            //out.print(jsoncallback+"({\"account\":\"aaaa\",\"passed\":\"true\",\"error\":\"null\"})");
           
            out.print(jsoncallback+"([{\"name\":\"zhangsan\",\"name1\":\"lisi\",\"name2\":\"wangwu\"}" +
                    ",{\"name\":\"zhangsan2\",\"name1\":\"lisi\",\"name2\":\"wangwu\"}," +
                    "{\"name\":\"zhangsan3\",\"name1\":\"lisi\",\"name2\":\"wangwu\"}])");
           
            out.close();
           
           
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

你可能感兴趣的:(Ajax)