After calling update.js i need to refresh the page again

Solved
Tobeje
New Member
2 0 0

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

Accepted Solution (1)

Accepted Solutions
IttantaTech
Shopify Partner
510 55 92

This is an accepted solution.

@Tobeje 

Delay reload of page in success function.

Like this:- 

setTimeout(function(){

window.location.href = '/cart';

},500);

Thanks,
Ittanta Technologies Pvt. Ltd. | Shopify Expert
If reply is helpful, please Like and Accept Solution.
To hire us, contact us at info@ittanta.com

View solution in original post

Replies 2 (2)
IttantaTech
Shopify Partner
510 55 92

This is an accepted solution.

@Tobeje 

Delay reload of page in success function.

Like this:- 

setTimeout(function(){

window.location.href = '/cart';

},500);

Thanks,
Ittanta Technologies Pvt. Ltd. | Shopify Expert
If reply is helpful, please Like and Accept Solution.
To hire us, contact us at info@ittanta.com

View solution in original post

Tobeje
New Member
2 0 0

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