Why is my ajax response JS redirect not working?

Posted 1 month 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.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.