提交表单后重定向并显示通知

时间:2019-04-21 18:33:34

标签: javascript php

我正在尝试在提交表单后重定向页面,然后显示一些通知。

这是我的代码:

$sql = $mysqli->query("UPDATE something.....");

$_SESSION['message'] = "Updates Successfully";
    header('location: index.php');
    exit(0);

还有通知脚本:

<script type="text/javascript">
        jQuery(document).ready(function($)
        {
            $("#success_msg_1").click(function(ev)
            {
                ev.preventDefault();

                var opts = {
                    "closeButton": true,
                    "debug": false,
                    "positionClass": "toast-bottom-left",
                    "onclick": null,
                    "showDuration": "300",
                    "hideDuration": "1000",
                    "timeOut": "5000",
                    "extendedTimeOut": "1000",
                    "showEasing": "swing",
                    "hideEasing": "linear",
                    "showMethod": "fadeIn",
                    "hideMethod": "fadeOut"
                };

                toastr.success("So me by marianne admitted speaking.", "This is a title", opts);
            });

        });
    </script>

但是页面只是重定向而已,没有通知。

1 个答案:

答案 0 :(得分:0)

您的通知是在按钮单击事件上设置的。如果要在加载新页面时显示通知,则应将烤面包机通知放置在文档中,而不是在按钮单击事件中。

像这样:

<script type="text/javascript">
        jQuery(document).ready(function($)
        {

                var opts = {
                    "closeButton": true,
                    "debug": false,
                    "positionClass": "toast-bottom-left",
                    "onclick": null,
                    "showDuration": "300",
                    "hideDuration": "1000",
                    "timeOut": "5000",
                    "extendedTimeOut": "1000",
                    "showEasing": "swing",
                    "hideEasing": "linear",
                    "showMethod": "fadeIn",
                    "hideMethod": "fadeOut"
                };

                toastr.success("So me by marianne admitted speaking.", "This is a title", opts);

        });
    </script>

还要确保您在其中包括了both the CSS and JS files for toastr