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(); ?>
messages
in your page. You may have to create it and insert it in the dom. – Marius♦ Nov 9 '15 at 12:33