jquery ajax 提交checkbox数组的方法


直接上代码,主要是获取checkbox值的方法:将其放到数组中,然后连接成字符串
var selectedItems = new Array();
$(“input[@name='itemSelect[]‘]:checked”).each(function() {selectedItems.push($(this).val());});
if (selectedItems .length == 0)
alert(“Please select item(s) to delete.”);
else
$.ajax({
type: “POST”,
url: “/ajax_do_something.php”,
data: “items=” + selectedItems.join(‘|’),
dataType: “text”,
success: function (request) {
document.location.reload();
},
error: function(request,error){
alert(‘Error deleting item(s), try again later.’);
}
}
);