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 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿