单击OK页面刷新时出现带有成功消息的codeIgniter Javascript警报 [英] codeIgniter Javascript alert with success message on click ok page refresh

查看:158
本文介绍了单击OK页面刷新时出现带有成功消息的codeIgniter Javascript警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码:

<div class="alert alert-success">
    <a class="close" data-dismiss="alert">×</a>
    <?php 

        $message = "Your Upload was successful";
        if((isset($message))&&($message!='')){
        echo '<script> alert("'.str_replace(array("\r","\n"), '', $message).'");      </script>';
        }
       redirect($this->uri->uri_string());  //refresh page
    ?>

我想显示此成功警报消息,然后,如果用户单击确定",它将刷新浏览器.就我而言,这只是刷新浏览器.

I want to show this success alert message and then if the user click on OK it will refresh the browser. In my case it is just refreshing the browser.

什么是最好的方法?

非常感谢.

推荐答案

要使代码按预期工作,您必须使用Javascript编写refresh函数,而不是使用PHP redirect函数,如下所示:

To make your code work as expected, you have to write the refresh function in Javascript instead of using PHP redirect function like the below:

<?php 
    $message = "Your Upload was successful";
    if ((isset($message)) && ($message != '')) {
        echo '<script>
            alert("'.str_replace(array("\r","\n"), '', $message).'");
            location.reload(true);
        </script>';
    }
?>

如果要使用Bootstrap模式,请尝试以下操作:

If you want to use Bootstrap modal, try this:

<?php
$message = "Your Upload was successful";
if ((isset($message)) && ($message != '')):
?>
<div class="modal" id="alert-dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Alert</h4>
            </div>
            <div class="modal-body">
                <?php echo $message; ?>
            </div>
            <div class="modal-footer">
                <button data-dismiss="modal" type="button" class="btn btn-primary">OK</button>
            </div>
        </div>
    </div>
</div>
<script>
$(function() {
    $('#alert-dialog').modal('show').on('hidden.bs.modal', function () {
        location.reload(true);
    });
});
</script>
<?php endif; ?>

这篇关于单击OK页面刷新时出现带有成功消息的codeIgniter Javascript警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆