• 显式提交/隐式提交 //ajax方式的隐式提交


    //创建jqueryAjax.html文件

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>//将js文件jquery-1.11.3.min.js导入到文件夹JS中     
    <script>
    function fn1(){
        $.get(
             "/day480/ajaxJquery",
             {"name":"qiang","age":20},
             function(data){
                 alert(data.name)
             },
             "json"
        );
    }
    function fn2(){
        $.post(
             "/day480/ajaxJquery",        
                 {"name":"tong","age":21},
                 function(data){
                     alert(data.name)
                 },
                 "json"
        );
    }
    function fn3(){
        $.ajax({
            url:"/day480/ajaxJquery",
            async:true,
            type:"POST",
            data:{"name":"zhangyi","age":19},
            success:function(data){
                alert(data.name)
            },
            error:function(){
                alert("请求失败");
            },
            dataType:"json"
        });
        
    }

    </script>
    </head>
    <body>
    <input type="button" value="显式提交 " onclick="fn1()"><span id="span1"></span>
    <input type="button" value="隐式提交 " onclick="fn2()"><span id="span2"></span>
    <input type="button" value="ajax隐式提交 " onclick="fn3()"><span id="span3"></span>
    </body>
    </html>

    //创建servlet    AjaxJquery       ajaxJquery

    package Demo;

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

    public class AjaxJquery extends HttpServlet {

        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
         request.setCharacterEncoding("utf-8");
         String name = request.getParameter("name");
         String age = request.getParameter("age");
            System.out.println(name+ "  " +age);
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().write("{"name":"tou头强","age":22}");
        }

        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {

            doGet(request, response);
        }

    }

  • 相关阅读:
    (转)导弹跟踪算法
    中文linux安装oracle界面乱码解决方案
    linux下创建oracle表空间
    [INS-20802] Oracle Net Configuration Assistant failed
    Centos6.5下Oracle 11g R2安装过程
    设置MYSQL数据库编码为UTF-8
    如何在linux系统中设置静态ip地址
    Oracle Net Configuration Assistant failed异常的解决方案
    解决安装oracle11g r2时提示pdksh conflicts with ksh-20100621-2.el6.i686问题
    CentOS增加swap分区大小
  • 原文地址:https://www.cnblogs.com/Fisherman13/p/10519623.html
Copyright © 2020-2023  润新知