我正在使用 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');
- 1 回答
- 0 關注
- 69 瀏覽
添加回答
舉報
0/150
提交
取消