未定义Toastr,javascript错误
在我的php项目中,我试图实现toastr通知。 当我只使用带有硬编码cdn资源的toastr设置时,它工作得很好。 但现在我用bower等将toastr包含到我的包中。 我正在使用最新版本的toastr,它有一个用于jquery3的修复程序+ 此时,所有需要的资源都包含在my bundle.js和bundle.css中 在我的脑海里:未定义Toastr,javascript错误,javascript,php,toastr,Javascript,Php,Toastr,在我的php项目中,我试图实现toastr通知。 当我只使用带有硬编码cdn资源的toastr设置时,它工作得很好。 但现在我用bower等将toastr包含到我的包中。 我正在使用最新版本的toastr,它有一个用于jquery3的修复程序+ 此时,所有需要的资源都包含在my bundle.js和bundle.css中 在我的脑海里: <link defer="defer" src="http://localhost:8080/GiveaDay/design/css/gad.bundle
<link defer="defer" src="http://localhost:8080/GiveaDay/design/css/gad.bundle.css"></script>
<script defer="defer" src="http://localhost:8080/GiveaDay/design/js/gad.bundle.js"></script>
但现在我在以下代码中得到错误“toastr未定义”:
<script>
window.addEventListener('DOMContentLoaded', function() {
(function($) {
$(document).ready(function() {
toastr.options = {
"closeButton": false,
"debug": false,
"newestOnTop": false,
"progressBar": true,
"positionClass": "toast-top-center",
"preventDuplicates": false,
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "5000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
}
});
})(jQuery);
});
<?php if($feedback['type'] == "alert-success"){ ?>
toastr.success("<?php echo $feedback['text']; ?>");
<?php }else if($feedback['type'] == "alert-danger"){ ?>
toastr.error("<?php echo $feedback['text']; ?>");
<?php } ?>
</script>
addEventListener('DOMContentLoaded',function(){
(函数($){
$(文档).ready(函数(){
toastr.options={
“closeButton”:false,
“调试”:错误,
“newestOnTop”:错误,
“progressBar”:没错,
“positionClass”:“toast top center”,
“防止重复”:错误,
“onclick”:空,
“showDuration”:“300”,
“隐藏”:“1000”,
“超时”:“5000”,
“extendedTimeOut”:“1000”,
“挥杆”:“挥杆”,
“隐藏”:“线性”,
“showMethod”:“fadeIn”,
“隐藏法”:“淡出”
}
});
})(jQuery);
});
成功(“”);
toastr.错误(“”);
我错过了什么
提前感谢您能为此创建代码段吗?您的js文件似乎没有连接到propper。检查gad.bundle.js中是否有toastr。@Brent用bundle.js中的代码片段更新了Q。它包含了比ofc更多的东西,只是为了表明它的存在。
<script>
window.addEventListener('DOMContentLoaded', function() {
(function($) {
$(document).ready(function() {
toastr.options = {
"closeButton": false,
"debug": false,
"newestOnTop": false,
"progressBar": true,
"positionClass": "toast-top-center",
"preventDuplicates": false,
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "5000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
}
});
})(jQuery);
});
<?php if($feedback['type'] == "alert-success"){ ?>
toastr.success("<?php echo $feedback['text']; ?>");
<?php }else if($feedback['type'] == "alert-danger"){ ?>
toastr.error("<?php echo $feedback['text']; ?>");
<?php } ?>
</script>