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.');

      }

    }

    )

 

你可能感兴趣的:(jQuery ajax)