Liquid, JavaScript, themes, sales channels
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
Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024Digital marketers and app developers have tracked activity in apps and websites for yea...
By Ollie Mar 13, 2024February was an exciting month with Shopify Editions, informative webinars, and more! F...
By JasonH Mar 7, 2024