donkey199024 2018-05-18 03:59
浏览 48
已采纳

如何使用AJAX将所有已检查的项目发送到php [复制]

This question already has an answer here:

How can I send all the checked item into php using AJAX. The info I expect to send including checkbox id and checkbox inner text. e.g. If I check box1 and box2, it could save the useful info into Data then sent to php when I click submit.

I try to use serialize() in javascript, however the Date has always been "".

var Data = $('#myform').serialize(); 

Please notice that I don not expect realtime respond when I check each box. I just wanna send the entire checked list after I click "submit".

<form class="myform" id="myform" action="add.php">
  <input type="checkbox" class="checkBox[]" id="1"> 1
  <input type="checkbox" class="checkBox[]" id="2"> 2
  <input type="checkbox" class="checkBox[]" id="3"> 3
  <input type="submit" class="add" id="add" name="add">
<form>

</div>
  • 写回答

1条回答 默认 最新

  • dory4404 2018-05-18 04:07
    关注

    Simply you can use this code

    var checkBox= new Array();
    $("input:checked").each(function() {
       data['checkBox[]'].push($(this).val());
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!