Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hello,
I have a problem with the Update.js call. I would like to use a button to set some variants to 0, which also works. The problem is that the page is reloaded after the post, but the variants are still there. After I have manually reloaded the page, they are gone.
What am I doing wrong, why do I still have to do a manual reload?
Here my Jquery snippet:
$.ajax({
type: 'POST',
url: '/cart/update.js',
data : { updates:
{
{{item.id}} : 0,
{% for p in item.properties %}
{% unless p.last == blank %}
{% if p.first contains '_item' %}
{{p.last}} : 0,
{% endif %}
{% if p.first contains '_free_item' %}
{{p.last}} : 0,
{% endif %}
{% endunless %}
{% endfor %}
},
dataType: 'json',
success: function() {
window.location.href = '/cart';
},
error: function(data){
console.log(data)
}
}
});
Thanks in advance
Tobeje
Solved! Go to the solution
This is an accepted solution.
Delay reload of page in success function.
Like this:-
setTimeout(function(){
window.location.href = '/cart';
},500);
This is an accepted solution.
Delay reload of page in success function.
Like this:-
setTimeout(function(){
window.location.href = '/cart';
},500);
I had tried this before and it didn't work. But I think I have now solved the problem elsewhere. The remove button was an html "a" tag, I think it had executed the page reload before. But anyway I accept this as the answer, because it is the solution to the code above 😉
Thanks
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024