I am using Store 2 as my e-commerce module, with the AJAX Form plugin to submit products to the cart.
My question is: Is there a way to detect if the item was added successfully and update the CSRF token?
I thought the below would work, but unfortunately not:
$(document).on('click', '.add-basket', function() {
$('.add-basket-form').ajaxForm({
success: updateCart,
dataType: 'json'
});
});
function updateCart(data, statusText, xhr) {
if (data.success) {
$("input[name=csrf_token]").val(data.csrf_token);
var url = 'http://www.domain.net/site/embed-mini-basket';
$('#masthead-mini-basket').load(url, function() {
alert('success');
});
} else {
alert('Failed');
}
}
Thanks.