CakePHP & jQuery, location.reload sometimes doesn't work

Hi, I am developing a data deletion page using a checkbox and a button. After deleting, I would like to show a message that the transaction was successful or not. In most cases, the message is displayed correctly, but sometimes the page does not reload, and the message does not appear until manually reloaded. Now, if it is not known whether the page is reloaded, is there another way to display a message from the controller? Here is 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>

(function control.php # delete ())

$this->Session->setFlash(__('Deleted!, true));
$this->redirect(array('action'=>'index'));
+2
source share
1 answer

CakePHP session flash is usually pretty reliable.

, location.reload(true). window.location = window.location.href + "?nocache=" + new Date().getTime() , .

+1

Source: https://habr.com/ru/post/1735174/


All Articles