在replaceWith之后无法提交ajax表单

时间:2014-10-06 17:08:07

标签: jquery html

我正在尝试创建一个购物车,这是我的购物车jquery

$(document).ready(function() {
    $(".ajaxform").submit(function(e) {

        $.ajax({
            url: "cart.php",
            type: "POST",
            data: $(this).serialize(),
            success: function(responseData, textStatus, jqXHR) {
                $(".cartrow").append("<div class=\"cart-row\">" + responseData + "</div>");
            },
            error: function(responseData, textStatus, jqXHR) {
                //if fails 
                alert("fail");
            }
        });
        e.preventDefault(); //STOP default action
        e.unbind(); //unbind. to stop multiple form submit.
    });

});

这是我用来提交表单的html表单

  <div class="product-tab" ID="disp"> <!-- bootstrap - min -->
                    <div class="product-detail fade active in " id="all" > <!-- bootstrap - min -->
                    <form class="ajaxform" method="post" ><h4><input type="hidden" name="pid[]"  value="1001">
                        <input type="hidden" name="unit"  value="10">onion(<del>&#2352;</del> 120)<hr></hr></h4>10<br><h6>
                        <label class="group"><input type="number" maxlength="2" name="quantity"/></label><h6>
                        <input type="submit" value="Add to cart" class="btn"></input><hr></hr></form>
                        </div>
            </div>

当我提交表单时,它工作正常,我可以将项目添加到我的购物车,但当我尝试使用下面的代码过滤我的项目时,添加到购物车按钮不会调用我的jquery添加项目到购物车

$(document).ready(function() {
     $('input[type="radio"]').on('change', function() {
         var selectedPrice = new Array();
         $('input[name="price"]:checked').each(function() {
             selectedPrice.push(this.value);
         });
         var brand = new Array();
         $('input[name="filter[]"]:checked').each(function() {
             brand.push(this.value);
         });

         $.ajax({
             url: 'no_product_filter.php',
             type: 'post',
             data: {
                 selectedPrice: selectedPrice,
                 brand: brand
             },
             success: function(response) {

                 $("#disp").replaceWith("<div class=\"product-tab\" id=\"disp\">" + response + "</div>");


             },
             error: function(response) {
                 alert("fail" + response);
             }
         });
     });
 });

有什么我不应该使用jquery replaceWith。我从我的PHP得到的上面提到的响应与我使用我的过滤器删除的html禁止项目的结构相同。请看看

0 个答案:

没有答案