Why is my ajax response JS redirect not working?

Posted 6 months ago by geerizzle

I have the following add to cart method, at present it is a two-step process so once added, a link is shown to the user to click to goto the checkout. But in some cases I want it to redirect automatically. I know at this point I could post submit and go from there but given it's setup using ajax I figured I'd stick a redirect in here.

But my window.location.replace doesn't work - any idea why?

     methods: {
     addToCart(id, price) {
                this.waiting = true
                axios.post('/add-to-cart', {id: id,}) //don't pass price as that is got from DB
                    .then(response => {
                        this.showCartLink = true
                        window.fbq('track', 'AddToCart', {value: price, currency: 'GBP',});

  watch: {
             cart: function() {
                this.waiting = false

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.