javascript Magento:如何在管理面板中使用 JS 显示标准错误/成功消息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6042303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Magento: how to show standard error/success message using JS in admin panel?
提问by silex
I can add error/success message to the Magento admin panel from server-side, for example,
我可以从服务器端向 Magento 管理面板添加错误/成功消息,例如,
Mage::getSingleton('core/session')->addError('***');
But how to show the same message on the client-side using JS? I mean standard way (of course I can create the same message box, but it's not a solution). For example when I need to show a status of some AJAX request. Any ideas?
但是如何在客户端使用 JS 显示相同的消息呢?我的意思是标准方式(当然我可以创建相同的消息框,但这不是解决方案)。例如,当我需要显示某个 AJAX 请求的状态时。有任何想法吗?
回答by silex
function showMessage(txt, type) {
var html = '<ul class="messages"><li class="'+type+'-msg"><ul><li>' + txt + '</li></ul></li></ul>';
$('messages').update(html);
}
The typecould be 'error', 'success', 'notice' or 'warning'. Enjoy!
该类型可以是“错误”,“成功”,“通知”或“警告”。享受!