CakePHP& jQuery,location.reload有时不工作 [英] CakePHP & JQuery, location.reload sometimes not working

查看:136
本文介绍了CakePHP& jQuery,location.reload有时不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在使用复选框和按钮开发数据删除页面。删除后,我想显示该消息或者事务是否成功。大多数时间消息显示正确,但有时页面重新加载不会发生,并且该消息将不会显示,直到手动重新加载。
现在如果不确定页面是否被重新加载,有没有其他方法来显示控制器的消息?
以下代码:

Hi I am developing data deleting page with checkbox and button. After deletion, I'd like to display the message either the transaction is successful or not. Most of the time the message shows correctly, but sometimes the page reload doesn't happen and the message won't show until manually reloaded. Now if it's not certain if the page is reloaded, is there any other way to show the message from the controller? Here's the code:

(index.ctp)

(index.ctp)

<script type="text/javascript">
$(document).ready( function() {
    $("#btn").click(function() {
        var ids = '';
        $('input[type="checkbox"]').each(function(){
            if(this.checked){
                ids = ids.concat(this.id).concat(',');
            }else{
                jAlert("Please choose items to delete");
            }
        });
        if (ids != ''){
            jConfirm('Delete?', 'Confirm',function(r){
                if(r==true){
                    ht = $.ajax({
                        url: 'items/delete/'.concat(ids),
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                    });
                    location.reload(true);
                }

            });
        }
    });
});
</script>






(controller.php#function delete


(controller.php#function delete())

$this->Session->setFlash(__('Deleted!, true));
$this->redirect(array('action'=>'index'));


推荐答案

CakePHP的会话闪存通常相当可靠。

CakePHP's session flash is usually pretty reliable.

也许您的浏览器不能可靠地用 location.reload(true)进行硬刷新。尝试 window.location = window.location.href +?nocache =+ new Date()。getTime()手动清除缓存,看看是否有帮助。

Perhaps your browser is not reliably doing a hard refresh with location.reload(true). Try window.location = window.location.href + "?nocache=" + new Date().getTime() to manually clear the cache and see if that helps at all.

这篇关于CakePHP&amp; jQuery,location.reload有时不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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