ajax提交

servlet

表单上
<td>
<a href="javascript:void(0)" onclick="deleteRecord()">
<span id="cardid"><%=map.get("cardid")%></span>删除</a></td>

jquery
<script type="text/javascript" src="js/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
    function deleteRecord() {
        var cardid = $(this).parent().html();
        alert(cardid);
        $.ajax({
            url : ‘cardid.do‘,
            type : "post",
            data : {
                ‘cardid‘ : cardid
            },
            dataType : ‘html‘,
            success : function(data, status) {
                $(‘#name_msg‘).html(data);
            }
        });
        window.location.reload();
    }
</script>

后台
    String cardid = request.getParameter("cardid");//HttpServletRequest request
View Code

 

struts2

前台
<%    List users = (List) request.getSession().getAttribute("users");
            for (int i = 0; i < users.size(); i++) {
%>
<td><a href="javascript:void(0)" onclick="deleteRecord(<%=((Users) users.get(i)).getId()%>)">删除</a></td>

jquery
<script type="text/javascript" src="js/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
    function deleteRecord(obj) {
       var userid=obj;    
       $.ajax({
            url : ‘deleteUser‘,
            type : "post",
            data : {
                ‘userid‘ : userid
            },
            dataType : ‘html‘,
            success : function(data, status) {
                $(‘#name_msg‘).html(data);
            }
        });   
        window.location.reload();    
    }
</script>

后台
HttpServletRequest request = (HttpServletRequest) ActionContext            .getContext().get(ServletActionContext.HTTP_REQUEST);
String userid = request.getParameter("userid");
View Code

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。