page goes to top after product added in cart by ajax

Tourist
5 0 1

We allow users to add items to the cart directly from the collections pages using ajax calls to cart/add.js.  This has always worked fine, but we noticed yesterday that after the call is successful, the page always scrolls back to the top.

It only seems to be affecting add.js.  We have other code that allows the user to remove the item from the same page and it calls change.js -- those calls seem to be unaffected.  The item is removed from the cart successfully without the page scrolling back to the top.

Is anyone else experiencing this or have any suggestions on how to correct it?

Shopify Partner
12442 1505 4496

Hello, @krish692 

Welcome to the Shopify community!
and Thanks for your Good question.

Please share your site URL,
So I will check and provide a solution here.

If helpful then please Like and Accept Solution.
Want to modify or custom changes on store Hire me.
- Feel free to contact me on bamaniyaketan.sky@gmail.com regarding any help
Shopify Expert | Skype : bamaniya.sky
PSD to Shopify | Shopify Design Changes | Shopify Custom Theme Development and Desing | Custom Modifications In to Shopify Theme | SEO & Digital Marketing
0 Likes
Tourist
5 0 1

Hello, 

please check the below link to check that scroll up.

https://aiwo.com/collections/supplements

0 Likes
Shopify Partner
12442 1505 4496

@krish692 

Thanks for it 

yes it can be done change custom code can you please check your code if are you enable or assing me

If helpful then please Like and Accept Solution.
Want to modify or custom changes on store Hire me.
- Feel free to contact me on bamaniyaketan.sky@gmail.com regarding any help
Shopify Expert | Skype : bamaniya.sky
PSD to Shopify | Shopify Design Changes | Shopify Custom Theme Development and Desing | Custom Modifications In to Shopify Theme | SEO & Digital Marketing
0 Likes
Tourist
5 0 1

Thank you!

 

Can you please tell me how to enable the code

0 Likes
Shopify Partner
12442 1505 4496

@krish692 

try something like this

<input type="button" value="Add to cart" class="add_to_cart" />
<script>
$(document).ready(function () {
        $(document).on('click','.add_to_cart',function(){
            var quantity = //add quantity selector here
            var id= // variant selecto here
            $.ajax({
                type: 'POST',
                url: '/cart/add.js',
                dataType: 'json',
                data: {id:id,quantity:quantity},
                success: function(){
                }
            });
        })
    });
</script>
If helpful then please Like and Accept Solution.
Want to modify or custom changes on store Hire me.
- Feel free to contact me on bamaniyaketan.sky@gmail.com regarding any help
Shopify Expert | Skype : bamaniya.sky
PSD to Shopify | Shopify Design Changes | Shopify Custom Theme Development and Desing | Custom Modifications In to Shopify Theme | SEO & Digital Marketing
0 Likes
Tourist
5 0 1

I have checked this but the issue in this is, cart count and product adding to the ajax cart drawer is not updating without the page refresh.

So I have tried like this in the image I attached. In this, I cant able to add multi-products to ajax.

krish692_0-1606548488980.png

 

0 Likes