Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用不同名称回显多个复选框值_Php_Ajax - Fatal编程技术网

Php 使用不同名称回显多个复选框值

Php 使用不同名称回显多个复选框值,php,ajax,Php,Ajax,我的HTML+JS: <head> <script type="text/javascript"> function passList() { var p=[]; $('input.first').each( function() { if($(this).attr('check

我的HTML+JS:

<head>
  <script type="text/javascript">
                function passList() {
                        var p=[];
                        $('input.first').each( function() {
                                if($(this).attr('checked')) {
                                        p.push($(this).attr('rel'));
                                }
                        } );
                        $.ajax( {
                                url:'process.php',
                                type:'POST',
                                data: {list:p},
                                success: function(res) {
                                $("#result").html(res);

                                }
                        });
                }

               function passType() {
                        var q=[];
                        $('input.second').each( function() {
                                if($(this).attr('checked')) {
                                        q.push($(this).attr('rel'));
                                }
                        } );
                        $.ajax( {
                                url:'process.php',
                                type:'POST',
                                data: {type:q},
                                success: function(res) {
                                $("#result").html(res);

                                }
                        });
                }

        </script>
</head>
<body>
        <input type="checkbox" class="first" rel="list1" onclick="passList()">list1<br />
        <input type="checkbox" class="first" rel="list2" onclick="passList()">list2<br />
        <input type="checkbox" class="first" rel="list3" onclick="passList()">list3<br />
        <input type="checkbox" class="first" rel="list4" onclick="passList()">list4<br />
       <br><br><br>
    <input type="checkbox" class="second" rel="type1" onclick="passType()">type1<br />
        <input type="checkbox" class="second" rel="type2" onclick="passType()">type2<br />
        <input type="checkbox" class="second" rel="type3" onclick="passType()">type3<br />
        <br><br><br> 

        <div id="result"> </div>        
</body>
我可以通过以下脚本获得div结果中的值:

if(isset($_POST['list']) && !isset($_POST['type'])) {
     foreach ($_POST['list'] as $list) {
      echo "this is $list<br />"; 
      }
    }
    else if(!isset($_POST['list']) && isset($_POST['type'])) {
     foreach ($_POST['type'] as $type) {
      echo "type is : $type<br />"; 
     }
    }
    else if(isset($_POST['list']) && isset($_POST['type'])) {
     foreach ($_POST['list'] as $list) {
      echo "Showing ads for $list<br />"; 
       foreach ($_POST['type'] as $type) {
       echo "type is : $type<br />"; 
      }
     }
    }
但是我得到列表或类型的值

我希望能够同时获得两者的值。我不想用电话

请帮忙


谢谢。

Anobody??请帮忙。。