我正在使用 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 关注
- 59 浏览
添加回答
举报
0/150
提交
取消