The controller takes the Ajax request and after some required operations should return the HTML of the notification message using message manager so that it can be rendered on the 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 to do is feasible?
If yes, then what have missed I or done wrong?

Thanks.