Redirecting after Ajax post

后端 未结 3 1607
自闭症患者
自闭症患者 2020-11-30 10:35

I want the success on ajax post to go to the home page. For some reason I keep doing it wrong. Any idea what I should do to fix this?

window.APP_ROOT_URL = \         


        
3条回答
  •  北海茫月
    2020-11-30 10:57

    Not sure why, but window.location.href did not work for me. I ended up using window.location.replace instead, which actually worked.

    $('#checkout').click(function (e) {
        e.preventDefault();
        $.ajax('/post/url', {
            type: 'post',
            dataType: 'json'
        })
        .done(function (data) {
            if (data.cartCount === 0) {
                alert('There are no items in cart to checkout');
            }
            else {
                window.location.replace('/Checkout/AddressAndPayment');
            }
        });
    });
    

提交回复
热议问题