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
The year-end shopping spree is around the corner! Is your online store ready for the ...
By JasonH Nov 10, 2024We recently spoke with Zopi developers @Zopi about how dropshipping businesses can enha...
By JasonH Oct 23, 2024A big shout out to all of the merchants who participated in our AMA with 2H Media: Holi...
By Jacqui Oct 21, 2024