0

I'm having a problem, I've placed an ajax Request in my cart, and she's doing what she has to do that is adding the product to the cart, but she does not redirect to the next page, she stands in the same place, so I added A submit function, but then add 2 products which would be what the functions has to do, how do I redirect to next screen without the submit?

view.phtml

            productAddToCartForm.submit = function(button, url) {
            if (this.validator.validate()) {
                var form = this.form;
                var oldUrl = form.action;

                if (url) {
                   form.action = url;
                }
                var e = null;

                if(!url){
                url = jQuery('#product_addtocart_form').attr('action');
                }
                url = url.replace("checkout/cart","ajax/index"); 
                var data = jQuery('#product_addtocart_form').serialize();
                data += '&isAjax=1';   
                jQuery('#ajax_loader').show();
                try {
                    jQuery.ajax({
                          url: url,
                          dataType: 'json',
                          type : 'post',
                          data: data,
                          success: function(data){
                                jQuery('#ajax_loader').hide();

                                if(jQuery('.block-cart')){
                                    jQuery('.block-cart').replaceWith(data.sidebar);
                                }
                                if(jQuery('.header .links')){
                                    jQuery('.header .links').replaceWith(data.toplink);
                                }
                          }
                    });
                } catch (e) {
                }

If I add this here it redirects the page, but adds 2 items

                this.form.submit();
                } catch (e) {
                }
0

Redirecting AJAX requests to another url does not affect the original page. The most simple solution would be to redirect using javascript on when AJAX result is returned.

success: function(data){
         //...
         //perform checks if needed
         window.location.href = '<?php echo Mage::getUrl("checkout/cart");?>';
}
  • can this be in M2 ? – Ajwad Taqvi Nov 16 '18 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.