分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

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

发布时间:2023-09-06 02:35责任编辑:熊小新关键词:暂无标签

//创建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);
    }

}

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

原文地址:https://www.cnblogs.com/Fisherman13/p/10519623.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved