douhuan7862 2016-01-16 07:43
浏览 35
已采纳

在CodeIgniter视图中使用jQuery noty for flashdata(页面重新加载)

I have been searching for ages but to no avail. I am trying to use jQuery noty in order to give failure notifications (instead of the standard Bootstrap notifications I have been using). I cannot for the life of me get how this is supposed to work. I want the notification to appear based on there being an error in the flashdata...

I am still very much in the learning stages of JavaScript / jQuery so its probably a dumb newbie mistake, I would appreciate any assistance that can be rendered!

Controller:

elseif ($usr_result['status'] == FALSE) {
    $this->session->set_flashdata('flashError', 'User not active, please contact your administrator');
    redirect('account/login');
}

View:

<?if($this->session->flashdata('flashError')):?>
    <script type="text/javascript">
        $.noty.defaults.killer = true;

        noty({
            text: '<?=$this->session->flashdata('flashError')?>',
            layout: 'top',
            type: 'error',
            closeButton: ['true']});
     </script>

<?endif?>

I have tested noty with a pressbutton:

<button class="btn btn-primary noty" data-noty-options='{"text":"This is an alert","layout":"top","type":"alert","closeButton":"true"}'><i class="halflings-icon white bell"></i> Bottom Full Width with Close Button</button>

and it works fine (so jQuery and noty are both loaded correctly)

  • 写回答

1条回答 默认 最新

  • douping3860 2016-01-16 09:25
    关注

    I'm not sure if this is the best way to achieve it, but after researching JavaScript (theres nowhere near enough documentation on noty to be anywhere near helpful for someone who isn't a JavaScript pro), I ended up doing this in my view to get it to work:

    <?if($this->session->flashdata('flashError')):?>
    <script type="text/javascript">
        function notify() {
            noty({
                text: '<?=$this->session->flashdata('flashError')?>',
                layout: 'top',
                type: 'error',
                closeButton: true,
                timeout: false
            });
        }
        window.onload = notify;
    </script>
    <?endif?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题
  • ¥15 有没有人能解决下这个问题吗,本人不会编程
  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗