0

I've created a button on magento2 admin. This button activates a controller using an Ajax request. I'm trying to display an overlay notification - or any other kind of message to the user that will indicate the success\failure of the operation. I thought that $('messages').update(html) will add a notification of some sort to the admin page i'm viewing - but it didn't show anything. How can I properly show a notification on the admin?

<script type="text/javascript">
    //<![CDATA[
    function exportOrders() {
    var params = {
                form_key : FORM_KEY,
                store_id : '<?php echo $this->getStoreId() ?>'
            };
    var url = '<?php echo $this->getAjaxExportUrl() ?>';

    new Ajax.Request(url , {
                parameters:params,
                method:'post',
                onComplete:function (transport) {
                if (transport.responseText == 1)  {
                    var html = '<ul class="messages"><li class="success-msg"><ul><li>' + 'Success!' + '</li></ul></li></ul>';
                        $('messages').update(html);
                } 
                else {
                    var html = '<ul class="messages"><li class="error-msg"><ul><li>' + transport.responseText + '</li></ul></li></ul>';
                        $('messages').update(html);    
                }
            }
        });
    }
    //]]>
</script>

<?php echo $this->getButtonHtml(); ?>
  • What problem do you have? (except beter to use jquery and reqirejs for js) – KAndy Nov 9 '15 at 10:04
  • I thought that $('messages').update(html) will add a notification of some sort to the admin page i'm viewing - but it didn't show anything. How can I properly show a notification on the admin? – Omry Zobel Nov 9 '15 at 12:29
  • maybe there is no element with the id messages in your page. You may have to create it and insert it in the dom. – Marius Nov 9 '15 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.