1

Controller takes the Ajax request and after some required operations should return the html of notification message using message manager so that it can be rendered on front end using Javascript.

    $_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $messageManager = $_objectManager->create('\Magento\Framework\Message\ManagerInterface');
    $block = $this->_layoutFactory->create()->getMessagesBlock()->addError('Configuration is wrong!');
    $block->setMessages($messageManager->getMessages(true));

    $resultJson = $this->resultJsonFactory->create();

    $mess= $block->getGroupedHtml();
    return $resultJson->setData([
        'messages' => $mess,
        'error' => '$error value comes here'
    ]);

But function getGroupedHtml() does not return any html.

Being a beginner to Magento, my queries are

What i am trying doing is feasible? If yes, then what i have missed or doing wrong?

Thanks.

0

Try remove line from your code:

$block->setMessages($messageManager->getMessages(true));

I don't know why you need it. Remove is should to help.

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.