Ad
How To Use Timber.RightDrawer.open(); In Custom Add To Cart Success To Open Drawer?
I am using add to cart with custom ajax code and its working fine, problem is I need to open cart drawer on success function by using timber.RightDrawer.open(); For now I am using "js-drawer-open-right" class in form but its open drawer same time when click on add to cart button. I need to open drawer on success of add to cart.
My Ajax code is:
function addItem(button) {
var postData = $(button).closest('.add-to-cart').serialize();
$.ajax({
type: 'POST',
url: '/cart/add.js',
dataType: 'json',
data: postData,
success: addToCartOk,
error: addToCartFail
});
}
function addToCartOk(product) {
//Want to open drawer here on success
timber.RightDrawer.open();
}
function addToCartFail(obj, status) {
}
My form is:
Here you can check Add to Cart https://soft-theme.myshopify.com/collections/all
Ad
Answer
I have find out different and very easy solution for this as compare to timber.RightDrawer.open();
I have clicked "js-drawer-open-right" with jQuery in success function and removed that class from form which I have placed before.
The success function now is:
function addToCartOk(product) {
//drawer open here by click on that class on success
jQuery('.js-drawer-open-right').click();
}
Its worked perfectly fine.
Ad
source: stackoverflow.com
Related Questions
- → OctoberCMS - How to make collapsible list default to active only on non-mobile
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → when i send data with ajax(jquery) i don't find the values in controller without form in laravel 5.1
- → DropzoneJS & Laravel - Output form validation errors
- → Knockout JS - How to return empty strings for observable fields
- → How to replace *( in a string
- → Get the calling element with vue.js
- → Sent Variable to Controller via Ajax in Blade
- → AJAX folder path issue
- → Onclick with argument causes javascript syntax error
- → KNockout JS - Automatic reload of ajax call
Ad