Skip to content

Instantly share code, notes, and snippets.

@atikju
Last active November 4, 2018 11:19
Show Gist options
  • Select an option

  • Save atikju/f5cf2d2f7a9b0331b2cb339cc3fb51c7 to your computer and use it in GitHub Desktop.

Select an option

Save atikju/f5cf2d2f7a9b0331b2cb339cc3fb51c7 to your computer and use it in GitHub Desktop.
Shopify Ajax - Add product to cart without loading the page
$('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