这是我写的批量删除的一段前端代码
//删除按钮
$(":button[value=删除]").click(function(){
var idlist="";
var idCount=0;
$(":checkbox[checked]").each(function(){
idlist = idlist+$(this).val()+',';
idCount++;
});
if(idCount==0){
alert("请选择删除对象!");
return ;
}
var r=confirm("确认删除"+idCount+"个联系人?");
if (r!=true)
{
idlist="";
return;
}
$(":checkbox[checked]").each(function(){
$("tr[id="+$(this).val()+"]").remove();
});
$.post(
"
{ids:idlist},
function(data){
var s = "删除数据"+idCount+"条,成功"+data+"条";
alert(s);
window.location.href="
}
);
});
});
这是action部分代码
private String ids;
private ContacterService service;
private InputStream inputStream;
public String execute(){
HttpSession session = request.getSession();
User user = (User) session.getAttribute("user");
if(this.ids==null||this.ids.trim().equals("")){
return ERROR;
}
String id[] = this.ids.split("\\,");
List
for(int i= 0;id != null && i < id.length ; i++){
if(id[i].length()==36){
list.add(id[i]);
}
}
//ContacterService service = ContacterServiceImplFactory.getInstance();
int count = this.service.deleteContacter(list);
inputStream = new StringBufferInputStream(count+"");
return SUCCESS;
}
public void setService(ContacterService service) {
this.service = service;
}
public String getIds() {
return ids;
}
public void setIds(String ids) {
this.ids = ids;
}
public InputStream getInputStream() {
return inputStream;
}
这是struts配置片段
text/html
inputStream
/WEB-INF/jsp/DeleteContacterError.jsp
可能的原因:1 你后台没有返回值 2 你ajax 的success 函数里没做接受数据 或后台返回的数据与接收的 数据类型不一致 3 后台有异常抛出 仔细调试回调,BDlXev
我有个例子 要的话就发个邮件到wzqiangde@163.com