Good day! Tell me why the AJAX script can not work in firefox? The script is responsible for sending the form data (adding goods to the basket), in Opera and Chrome everything is fine. And in firefox, the form redirects to the link in action because of what I get 404 and the product does not fall into the basket.

$('.main-wrap').on('submit','form#add-product',function() { event.preventDefault(); var a = null, e = null, t = $(this), n = t.find('button[type="submit"]'), r = t.find('input[name="variant"]:checked'), s = t.find('select[name="variant"]'), i = t.find('select[name="size"]'), u = t.find('input[name="size"]:checked'), l = t.find('input[name="amount"]'); console.log(a = r.val()); console.log(e = u.val()); console.log(l.val()); r.size() > 0 && (a = r.val()), l.size() > 0 && (amount = l.val()), s.size() > 0 && (a = s.val()), u.size() > 0 && u.val() > 0 && (e = u.val()), i.size() > 0 && (e = i.val()), 0 != e ? $.ajax({ url: "ajax/cart.php", data: { variant: a, size: e, amount: amount }, dataType: "json", success: function(a) { // $(".error-message").hasClass("size-error") && $(".error-message").removeClass("size-error"), console.log(a['c']); console.log(a['p']); $(".cart-btn").html(a['c']).addClass('cart--active'); $('.popup__body').html(a['p']); } }) : $(".error-message").addClass("size-error") 

});

 <form id="add-product" action="/cart"> {if $product->sizes|count > '1'} <div class="product__size-list"> {foreach $product->sizes as $v} <input id="size-n-{$v->size_id}" class="product__size-checkbox display--hidden" name="size" type="radio" value="{$v->size_id}"> <label for="size-n-{$v->size_id}" class="product__size-item"> {$v->scale}{if $v->growth}&nbsp;({$v->growth}){/if} </label> {/foreach} </div> {/if} <div style="display: none;"> <input name="variant" value="{$product->variant->id}" type="radio" checked style="display: none;" /> </div> <div class="product__quantity"> <span class="btn-m btn-minus"> <i class="fa fa-minus" aria-hidden="true"></i> </span> <input class="display--hidden" type="text" name="amount" value="1"> <span class="quantity__count">1</span> <span class="btn-m btn-plus"> <i class="fa fa-plus" aria-hidden="true"></i> </span> </div> </form> 

    1 answer 1

    Firefox does not have a global event object. Fortunately, jQuery event handlers get it as the first parameter in all browsers.

     $('.main-wrap').on('submit','form#add-product',function(event) { event.preventDefault(); ... 
    • And what to do? How to run, what would it all work? - E_K
    • one
      @ AFI19 hmm, I wrote. Carefully compare your and my lines of code. Okay, first line :). - Igor
    • Thank you, it works. Immediately not noticed. - E_K