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?
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.
Thanks for it
yes it can be done change custom code can you please check your code if are you enable or assing me
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>
User | Count |
---|---|
804 | |
121 | |
93 | |
93 | |
70 |