为了账号安全,请及时绑定邮箱和手机立即绑定

如何显示带有动态变量的 toastr 消息

如何显示带有动态变量的 toastr 消息

PHP
暮色呼如 2022-10-28 15:26:42
我正在使用 Toastr 在 UI 中显示消息弹出窗口。我通过 Ajax 向服务器发送请求,作为响应,我发送以下响应echo json_encode(                    array(                            "type" => "error",                            "message" => $error,                            "status" => "Error While Updating!"                         )                );我正在使用 resp.type 来显示动态 toastr 所以下面是我的 toastr 代码.done(function(resp)    {        toastr.resp.type(resp.message, resp.status,{progressBar:!0,showMethod:"slideDown",hideMethod:"slideUp",timeOut:2e3,preventDuplicates: true,positionClass: "toast-bottom-right"});    });上面代码的问题是,当代码运行时,它会抛出一个错误消息Uncaught TypeError: toastr.type is not a function任何人都可以帮我解决问题所在或此处可能是正确的解决方案
查看完整描述

1 回答

?
慕的地10843

TA贡献1785条经验 获得超8个赞

你不能嵌入toastr.resp.type,它是无效的,因此会抛出一个错误。


据我了解,下面的代码可以按您的意愿工作


.done(function(resp)

   {

       toastr[resp.type](resp.message, resp.status,{progressBar:!0,showMethod:"slideDown",hideMethod:"slideUp",timeOut:2e3,preventDuplicates: true,positionClass: "toast-bottom-right"});

   });

请将此视为参考:https ://github.com/CodeSeven/toastr/issues/203


function showToast(message, timeout, type) {

      type = (typeof type === 'undefined') ? 'info' : type;

      toastr.options.timeOut = timeout;

      toastr[type](message);

  }


showToast('Hello Toastr!", 15000, 'warning');


查看完整回答
反对 回复 2022-10-28
  • 1 回答
  • 0 关注
  • 59 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号