jquery ajax:从表单提交选定的值

时间:2022-09-26 10:52:43

I have a form like this and i need to submit all values in this form except those with class="noDisplay". Pass it to the controller and update the value to "pd-price". Everything works fine, just that i cannot find a way to ignore the noDisplay values to submit the form.

我有一个这样的表单,我需要提交此表单中的所有值,除了那些class =“noDisplay”。将其传递给控制器​​并将值更新为“pd-price”。一切正常,只是我找不到忽略noDisplay值来提交表单的方法。

     <div class="cart">
                        <strong>
                            <span class="pd-price">80.407.000đ</span>
                        </strong>

       </div>     


  <form method="post" id="product-details-form" action="xxx">
        <ul>
     <li class="showImg-target noDisplay">
        <input type="radio"  name="product_attribute_46_3_113"> [+3.870.000]
     </li>
     <li class="showImgtarget">
<input type="radio" name="product_attribute_46_4_113">[+1.000.000]</li>

   <li  class="showImgtarget noDisplay">
<input type="radio"  name="product_attribute_46_5_113">[-1.500.000]</li>
    <li  class="showImgtarget noDisplay">
<input type="radio"  name="product_attribute_46_6_113"></li>

                            ..... a lot more 

                                   </ul>
                        </form>


 <script type="text/javascript">
      $(function () {
         updateStatus();
         $('*[name^=product_attribute]').change(function () {
         updateStatus();
         });

       function updateStatus() {
         $.ajax({
                  cache: false,
                  url: '/Catalog/UpdateProductStatus',
                  data: $('#product-details-form').serialize(),
                 type: 'post',
                 success: function (data) {
                 $('.summary-info').html(data.View);
                 $('.pd-price').html(data.Price);
                  $('.powered-icon').replaceWith(data.Pictures);
                        }
                                            });
                                        }
                                    });
                                </script>

1 个解决方案

#1


1  

You can use :not() selector:

您可以使用:not()选择器:

$('#product-details-form li:not(.noDisplay) :input').serialize();

#1


1  

You can use :not() selector:

您可以使用:not()选择器:

$('#product-details-form li:not(.noDisplay) :input').serialize();