zoukankan      html  css  js  c++  java
  • 使用$.post方式来实现页面的局部刷新功能

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery-3.3.1.min.js"></script>
    <script>
    function fun() {
    $.post("ajaxServlet",{username:"light",age:15},function (data) {
    alert(data);
    },"text");
    }

    </script>
    </head>
    <body>
    <input type="button" value="发送异步请求" onclick="fun();">
    <input type="text">
    </body>
    </html>

    package cn.hopetesting.com;

    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.IOException;

    /**
    * @author newcityman
    * @date 2019/9/16 - 21:53
    */
    @WebServlet("/ajaxServlet")
    public class AjaxServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String username = request.getParameter("username");
    /* try {
    Thread.sleep(5000);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }*/
    System.out.println(username);
    response.getWriter().write("hello,"+username+".");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    this.doPost(request, response);
    }
    }
     
  • 相关阅读:
    【并查集】亲戚
    【图论】Car的旅行线路 NOIP 2001
    【贪心】排座椅
    【DP】花店橱窗布置
    【NOIP】NOIP考纲总结+NOIP考前经验谈
    【NOIP】考前须知
    NOIP 2016 PJ T4 魔法阵
    NOIP 2016 PJ T3 海港
    【高精度】麦森数 NOIP 2003
    【带权并查集】食物链 NOIP 2001
  • 原文地址:https://www.cnblogs.com/newcityboy/p/11530977.html
Copyright © 2011-2022 走看看