How to send a checkbox group via ajax in jquery?

前端 未结 4 832
暗喜
暗喜 2021-01-14 07:39

I need to send a group of checkboxes (with some other data as well) via ajax in jquery.

What I\'ve done so far is:

var arr = $(\'#somediv input[type         


        
4条回答
  •  清酒与你
    2021-01-14 08:28

    Use serialize(), as val() just takes the value of the first element in the jquery collection. http://api.jquery.com/serialize/

    var postdata = $('#somediv input[type="checkbox"]').serialize();
    $.post("/somephpfile.php", postdata, function(data) {...
    

提交回复
热议问题