JQuery发送ajax请求不能用数组作为参数,否则会接收不到参数,
一、js代码如下:
$(‘#delete-button‘).click(function(){
var selectedMembers = document.getElementsByName(‘selectedMembers‘);
var cwIds = new Array(); //定义数组
for(var i=0;i<selectedMembers.length;i++){
if(selectedMembers[i].checked)
cwIds.push(selectedMembers[i].value); //创建新数组并添加元素
}
var cwId = cwIds.join(","); //将新数组变成字符串类型
if(cwIds.length==0){
alert(‘请选择最少一条记录‘);
return false; //如果不成功则退出
}
$.post(‘${pageContext.request.contextPath}/cw/deleteCw‘,{cwId:cwId},function(msg){
if(msg){ alert("删除成功"); window.location.reload(); //ajax发送请求成功后即刻刷新页面并且把以前选中的取消选中
var elements = document.getElementsByName(‘selectedMembers‘);
if(elements){
for(var i = 0; i < elements.length; i++){
elements[i].checked = false;
}
}
}
else alert("删除失败");
});
});