开发者

CakePHP & JQuery, location.reload sometimes not working

开发者 https://www.devze.com 2023-03-12 12:01 出处:网络
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 correct

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)

<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())

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


CakePHP's session flash is usually pretty reliable.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消