Question

I'm trying to redirect a form to checkout after clicking ajax submit request.

I'm able to reach the controller, but I can't redirect to checkout.

Here is my code:

 public function execute(){
        $post = $this->getRequest()->getPostValue();
        if($post){
            $this->logger->info(print_r($post)); 
            $cartUrl = $this->_url->getUrl('checkout/cart/index');
            $this->_responseFactory->create()->setRedirect($cartUrl)->sendResponse();            
            exit;
        }
         else{
            $this->logger->info("No data");   
         }
    
    }

It's not redirecting to checkout

I'm using \Magento\Framework\UrlInterface $url

Was it helpful?

Solution

in your ajax success function you can use jquery code

for e.g. window.location.href='your checkout url';

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top