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!');

    $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?



Try remove line from your code:


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

| improve this answer | |

Here It is Hope this will help You

define ([
], function ($, customerData) {
    'use strict';

    return function () {
        var msg = 'some message here';

        customerData.set('messages', {
            messages: [{
                type: 'success',
                text: msg
| improve this answer | |

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.