首页 > 代码库 > ajax提交

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="http://www.mamicode.com/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="http://www.mamicode.com/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

 

ajax提交