Toastr没有定义,javascript错误

时间:2018-06-07 07:42:21

标签: javascript php toastr

在我的php项目中,我正在尝试实现toastr通知。 当我只使用带硬编码的cdn资源的toastr设置时,它工作正常。 但是现在我正在使用bower等将toastr包含在我的捆绑包中。 我正在使用最新版本的toastr,它具有与Jquery 3 +

一起使用的修复程序

此时所有需要的资源都包含在我的bundle.js和bundle.css中 在我脑海里:

<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>

包含toast的bundle.js的一部分: (不粘贴整个吐司代码)

    /*
 * Toastr
 * Copyright 2012-2015
 * Authors: John Papa, Hans Fjällemark, and Tim Ferrell.
 * All Rights Reserved.
 * Use, reproduction, distribution, and modification of this code is subject to the terms and
 * conditions of the MIT license, available at http://www.opensource.org/licenses/mit-license.php
 *
 * ARIA Support: Greta Krafsig
 *
 * Project: https://github.com/CodeSeven/toastr
 */
/* global define */
(function (define) {
    define(['jquery'], function ($) {
        return (function () {
            var $container;
            var listener;
            var toastId = 0;
            var toastType = {
                error: 'error',
                info: 'info',
                success: 'success',
                warning: 'warning'
            };

            var toastr = {
                clear: clear,
                remove: remove,
                error: error,
                getContainer: getContainer,
                info: info,
                options: {},
                subscribe: subscribe,
                success: success,
                version: '2.1.3',
                warning: warning
            };

            var previousToast;

            return toastr;

但现在我在下面的代码中得到错误“toastr is not defined”:

    <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>

我在这里缺少什么?

提前致谢

0 个答案:

没有答案