I need add an errorMessage or successMessage on checkout/cart after an jquery validation. I tried require file 'Magento_Ui/js/model/messageList' for this but not have success.

My code:

    function ($, messageList) {
           type: "GET",
           url: /route/controller,
           async: false,
           success: function (res) {
               if (res.val) {
                  messageList.addErrorMessage({'message': messageError});

3 Answers 3


I'm not sure if you already solved this or not, but here it goes anyway. While Rakesh might be right (a controller is the preferred way), it doesn't answer the question. I found the easiest way of doing this is through the customerData object:

customerData.set('messages', {
    messages: [{
        type: 'success',
        text: 'Hello World'

I did this approach for after page load message display:

     define(['uiRegistry', 'mage/translate'], function(uiRegistry, $t) {
         let msgComponent = uiRegistry.get('index = messages');
         msgComponent.messages().messages = [];
            type: 'warning',
            text: $t('You are not allowed to edit this user.')

You can use type as 'error', 'warning', 'success', etc...


Add success message in your controller it will automatically display in your page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.