【问题标题】:How to Show a toastr message with dynamic variables如何显示带有动态变量的 toastr 消息
【发布时间】:2020-03-13 07:29:11
【问题描述】:

我正在使用 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的错误信息

谁能帮我看看这里出了什么问题或者什么可能是正确的解决方案

【问题讨论】:

    标签: javascript php jquery toastr


    【解决方案1】:

    你不能嵌入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');
    

    【讨论】:

      猜你喜欢
      • 2016-06-22
      • 2016-08-22
      • 1970-01-01
      • 1970-01-01
      • 2013-02-04
      • 1970-01-01
      • 1970-01-01
      • 2022-10-07
      • 1970-01-01
      相关资源
      最近更新 更多