Discussions

"Add to cart" form using AJAX

Anyone edited the "Add to cart" form in order to use AJAX to insert products in the cart without reloading the page and showing a "Product added to cart" message popup in the center of the page?

Any hint on how to do that?

Posted: Nov 4, 2012

Comments

Copyfight on November 8, 2012

I "hijacked" the form.commerce-add-to-cart input.form-submit button's click function with jQuery and now when the user click it a popup message appears to her:

(function($) {
        $(document).ready(function() {
                $("form.commerce-add-to-cart input.form-submit").click(function() {

                        $("div#my-popup").slideToggle().delay(8000).fadeOut();
                        return false;

                });
        });
})(jQuery);

Now I just need a way to submit the commerce-add-to-cart form via jQuery.

How can I do that? AJAX call?

Thank you for any hint.

Greetings, Giovanni