• return void ajax


    复制代码
    public class UserInfo {
        private String name;
        private Integer age;
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public Integer getAge() {
            return age;
        }
    
        public void setAge(Integer age) {
            this.age = age;
        }
    }
    复制代码
    复制代码
    @Controller
    public class json {
    @RequestMapping("/tojson")
        public void write(HttpServletRequest request, HttpServletResponse response) throws IOException {
        List<UserInfo> list=new ArrayList<UserInfo>();
        UserInfo u1=new UserInfo();
        u1.setName("啊啊");
        u1.setAge(22);
    
        UserInfo u2=new UserInfo();
        u2.setName("哈哈");
        u2.setAge(20);
    
        list.add(u1);
        list.add(u2);
    
    
        String re= JSON.toJSONString(list);
    
        response.getWriter().write(re);
    
    
    
        }
    
    }
    复制代码
    复制代码
    <%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
    <html>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.12.4.js"></script>
    <script type="text/javascript">
        $(function () {
            $.ajax({
                url:"${pageContext.request.contextPath}/tojson",
                type:"post",
                data:{},
                success:function (data) {
                    alert(data);
                }
    
            });
        });
    
    
    
    </script>
    <body>
    <h2>流氓</h2>
    </body>
    </html>
    复制代码
  • 相关阅读:
    HDU 4913 Least common multiple
    HDU 4915 Parenthese sequence
    HDU 2459 Maximum repetition substring
    HDU 5727 Necklace
    HDU 5724 Chess
    HDU 5726 GCD
    hihoCoder1033 交错和 数位DP
    2016百度之星资格赛题解
    10LaTeX学习系列之---Latex的文档结构
    09LaTeX学习系列之---Latex 字体的设置
  • 原文地址:https://www.cnblogs.com/zfx123--/p/7402440.html
Copyright © 2020-2023  润新知