<script type="text/javascript" src="js/jquery.js"></script>
    <script>
        function fun(){
            $.ajax({
                url:"ser1",//servlet路径
                type:"post",//请求方式 默认get
                data:{
                    uname:"lwx",
                    age:18
                },
                success:function (data){
                    //回调函数
                    console.log(data);
                },
                error:function (error){
                    console.log(error);
                },
                dataType:"text"//返回值的类型 json text
            });
        }
        function funGet(){
            //$.get(url,data,callback,type)
            $.get("ser1",{uname:"lwx"},function (data){
                console.log(data);
            },"text");
        }

        function funPost(){
            //$.post(url,data,callback,type)
            $.post("ser1",{uname:"lwx"},function (data){
                console.log(data);
            },"text");
        }
    </script>
@WebServlet("/ser1")
public class ser1 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String uname=req.getParameter("uname");
        System.out.println(uname);
        resp.getWriter().write(uname);
    }
}
版权声明:本文为lwx_R原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/lwx11111/p/16216204.html