Magento 2 controller redirect on button click in phtml file
0
I want to redirect customer using controller when button is clicked in one of my phtml files. So far I got, controller: public function execute(){ return $this->addToCart(); } public function addToCart(){ // some logic $this->_redirect('checkout/cart/index'); } The above is working fine (redirecting) when you access the controller via URL (www.mydomain.com/batchorder/index/addtocart). And here is my .phtml file: $("#addToCart").click(function(){ let controllerUrl = "<?php echo $block-getUrl('batchorder/index/addtocart'); ?>" $.post(controllerUrl, { "products": JSON.stringify(sideCart.SideCartProducts) }) The post request returns my logic as it should, however, it is not redirecting. Anyone can help?
...