I am submitting the form by ajax. It's working properly but I have one issue with the success message.

After ajax success, I have to display success message like default Magento2. How can I achieve this?

    url: "<?php echo $block->getUrl('frontname/order/save'); ?>",
    type: "POST",
    dataType: "text",
    data: "cancel= " + orderJSON,
    showLoader: true,
    success: function () {
    $("#" + id).remove();

1 Answer 1

define(['Magento_Customer/js/customer-data'], function (customerData) {
customerData.set('messages', {
    messages: [{
        text: 'message to display',
        type: 'success'

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.