dongnao2048 2018-06-05 15:50
浏览 119

插入多个复选框值php ajax

Please help me, This matter ruined my days . I tried with ajax and php, post these codes in previous thread, but can't get answer or any guide. I think my question or code are unclear. So here I Post what I actually need. Please help me or provide any links that helps.

HTML. It is dynamic and would be generated from php

<li>
<input type="checkbox" name="menu[]" value="News">News
    <ul>
        <li>
        <input type="checkbox" name="menu[][]" value="politics">Politics
        </li>
        <li>
        <input type="checkbox" name="menu[][]" value="Social">Social
        </li>
    </ul>
</li>
<li>
<input type="checkbox" name="menu[]" value="Views">Views                                 
</li>
<li>
<input type="checkbox" name="menu[]" value="Art">Art                               
</li>

<form>
</form>

While inserting multiple values it should be inserted as follow. If each menu has subcategory, then each checked value would be inserted in subcat_id, if has not then Null value.

enter image description here

What I tried :

Ajax

$(document).on('submit', '#form', function(e){
    e.preventDefault();
    var navid = [];
        $("input[name='menu[]']:checked").each(function(){
            navid.push(this.value);
        });
    var subnavid = [];
        $("input[name='menu[][]']:checked").each(function(){
            subnavid.push(this.value);
        });
        var formData = new FormData(this);
        formData.append('navid', navid);
        formData.append('subnavid', subnavid);
            $.ajax({
                type: 'POST',
                url: 'upload.php',
                data: formData,
                contentType: false,
                cache: false,
                processData:false,
                success: function(data){
                    alert(data);
                }
            });
      });

PHP

$data = explode("," ,$_POST["navid"]); 
subdata = explode("," ,$_POST["subnavid"]);
foreach ($data AS $key => $menu){
   foreach($subdata AS $k => $submenu){
   ......
   ......
   }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?