Last active
November 4, 2018 11:19
-
-
Save atikju/f5cf2d2f7a9b0331b2cb339cc3fb51c7 to your computer and use it in GitHub Desktop.
Shopify Ajax - Add product to cart without loading the page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $('form.add_to_cart').on('submit', function(event){ | |
| //debugger; | |
| event.preventDefault(); | |
| var postUrl = $(this).attr('action'); | |
| var postData = $(this).serialize(); | |
| //console.log(postData); check what your form posts | |
| $.ajax({ | |
| type: "POST", | |
| url: postUrl, | |
| data: postData, | |
| dataType: "json", | |
| success: function(data) { | |
| console.log('Product Added to Cart'); | |
| //do other things.. | |
| }, | |
| error: function() { | |
| console.log('error handling here'); | |
| } | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment