Struts2 同ajax发送多个id到后台,进行批量删除

来源:互联网 发布:ios 元数据丢失 编辑:程序博客网 时间:2024/06/12 23:21

html 删除

<input type="checkbox" id="id" name="id"/>

js获取值

// 获取勾选的复选框function getCheckboxList() {    var strIds = "";        $('input[name=id]:checked').each(function(){            strIds += $(this).val() + ",";        });        if(strIds.length > 0) {        strIds = strIds.substring(0, strIds.length - 1);    }    return strIds;}  
function doAsyncBatchDelete() {    if ( confirm("确认要删除?") ) {        var strIds = getCheckboxList("selectedRow");        if(strIds.length > 0) {            $.ajax({                 type: "post",                 url: root + "/test/deleteAsync",                 data :{                    "strIds" : strIds                },                cache: false,                 async:false,                 dataType: "json",                 success: function(data){                     if(data.success) {                        window.parent.frames[ "mainFrame"].location.reload(true);                      } else {                        alert(data.msg);                    }                }             });        } else {            alert("请勾选需要删除的数据!");        }    }}

Action 对接获取参数的方法

public void deleteAsync() throws SysException {        HttpServletRequest request = getHttpServletRequest();        String[] strIds = request.getParameterValues("strIds");        if(strIds != null && strIds.length > 0) {            // 1. 校验该角色是否被使用,如果被使用,给出提示不能删除            try {                // 2. 做你的删除操作            } catch (Exception e) {                e.printStackTrace();            }        }    }
原创粉丝点击