Php jquery ajax只提交第一个值

Php jquery ajax只提交第一个值,php,jquery,ajax,Php,Jquery,Ajax,我正在使用jquery和ajax提交表单。我有我的第一个选择菜单,根据此选择菜单的值,包含不同菜单的div将变为可见 <table> <tr> <td> <select required="" class="input-medium" id="foulTypes" name="foul" data-original-title="" title=""> <option val

我正在使用jquery和ajax提交表单。我有我的第一个选择菜单,根据此选择菜单的值,包含不同菜单的div将变为可见

 <table>
    <tr>
       <td>
          <select required="" class="input-medium" id="foulTypes" name="foul" data-original-title="" title="">
            <option value="">Select Foul</option>
            <option value="85">AID - Aiding Runner</option>
            <option value="1">BAT - Illegal Bat</option>
            <option value="2">BBW - Block Below Waist</option>
            <option value="3">BOB - Blocking Out of Bounds</option>
            <option value="4">CHB - Chop Block</option>
          </select>
        </td>
    </tr>
 </table
 <script>
     var foulTypes = $('#foulTypes');
     var select = this.value;
     foulTypes.change(function () {
        //We first disable all, so we dont submit data for more than 1 category
        $("#catDPI, #catILF, #catOPI, #catOH, #catDH, #catILD, #catUNS, #catUNR, #catTGT").hide().find(".category").attr("disabled", true);
        var $divSelectedCategory;
        if ($(this).val() == '1') {
            $divSelectedCategory = $("#catDPI");
            $('#catDPI').show();
        } else {
            $('#catDPI').hide();
        }

        if ($(this).val() == '85') {
          $divSelectedCategory = $("#catILF");
          $('#catILF').show();
        } else {
          $('#catILF').hide();
        }

        if ($(this).val() == '2') {
          $('#catOPI').show();
          $divSelectedCategory = $("#catOPI");
        } else {
          $('#catOPI').hide();
        }

        //We now enable only for the selected category        
        $divSelectedCategory.show().find(".category").attr("disabled", false).val('');
 });    
 </script>

  <div id="catDPI" style="display:none;">
      <select name="category" id="dpiCategory" class='category' style="width:210px;">
            <option value="Playing Through Receiver">Playing Through Receiver</option>
            <option value="arm bar">arm bar</option>
            <option value="Grabbing">Grabbing</option>
      </select>
  </div>

  <div id="catILF" style="display:none;">
     <select name="category" id="ilfCategory" class='category' style="width:210px;">
         <option value="">Select</option>
         <option value="moving">Moving</option>
         <option value="illegal">Illegal</option>
          <option value="standing">Standing</option>                                           
     </select>
  </div>

  <div id="catOPI" style="display:none;">
    <select name="category" id="opiCategory" class='category' style="width:210px;">
        <option value="">Select</option>
        <option value="restrict">Restrict</option>
        <option value="holding">Holding</option>
    </select>
  </div>
我不确定我做错了什么。是时候把它送给专家了!!我感谢你的帮助

尝试更改函数“foulTypes”并在visible select中添加类

foulTypes.change(function () {
        //We first disable all, so we dont submit data for more than 1 category
        $("#catDPI, #catILF, #catOPI, #catOH, #catDH, #catILD, #catUNS, #catUNR, #catTGT").hide().find(".category").attr("disabled", true);
        var $divSelectedCategory;
        if ($(this).val() == '1') {
            $divSelectedCategory = $("#catDPI");
            $('#catDPI').show();
            $('#dpiCategory').addClass("visible");
        } else {
            $('#catDPI').hide();
            $('#dpiCategory').removeClass("visible")
        }

        .... CONTINUE
在您的ajax提交中

var category = $(".category.visible").val();
尝试更改函数“foulTypes”并在visible select中添加类

foulTypes.change(function () {
        //We first disable all, so we dont submit data for more than 1 category
        $("#catDPI, #catILF, #catOPI, #catOH, #catDH, #catILD, #catUNS, #catUNR, #catTGT").hide().find(".category").attr("disabled", true);
        var $divSelectedCategory;
        if ($(this).val() == '1') {
            $divSelectedCategory = $("#catDPI");
            $('#catDPI').show();
            $('#dpiCategory').addClass("visible");
        } else {
            $('#catDPI').hide();
            $('#dpiCategory').removeClass("visible")
        }

        .... CONTINUE
在您的ajax提交中

var category = $(".category.visible").val();

你的
标签在哪里?我正在通过ajax提交。您可以看到.submit函数。这是我的表格标签,你能做一把小提琴吗?查找错误
var category=$(“.category”).val()有点困难
将返回带有
class=“category”
(不是启用和可见的元素)@StephenMuecke的第一个元素的值,因此在下面的示例中,我添加了一个class to use标志。您的
标记在哪里?我通过ajax提交。您可以看到.submit函数。这是我的表格标签,你能做一把小提琴吗?查找错误
var category=$(“.category”).val()有点困难
将使用
class=“category”
(不是启用和可见的元素)@StephenMuecke返回第一个元素的值,因此在下面的示例中,我添加了一个class to use flag。我认为使用此css技巧,您将获得一个值visible select。但是这个方法不是发送数据的最佳形式。hide()和show()可以正常工作。如果foulTypes发生变化,将显示正确的div和category select菜单。在可见类别上选择的选项值未通过。不理解我的想法。如果添加该类,不影响是否显示,但用于选择实际可见的选项,则该类的名称仅供参考。在您的示例中,当您获得.category的值时,会选择category类。这类似于使$(“.category:visible”)但如果您将此css属性用于此情况,则会选择nose。完成示例的其余部分并尝试!我认为通过这个css技巧,您可以获得visible select的值。但是这个方法不是发送数据的最佳形式。hide()和show()可以正常工作。如果foulTypes发生变化,将显示正确的div和category select菜单。在可见类别上选择的选项值未通过。不理解我的想法。如果添加该类,不影响是否显示,但用于选择实际可见的选项,则该类的名称仅供参考。在您的示例中,当您获得.category的值时,会选择category类。这类似于使$(“.category:visible”)但如果您将此css属性用于此情况,则会选择nose。完成示例的其余部分并尝试!