亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何顯示帶有動態變量的 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 關注
  • 69 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號