Yoshioka
Yoshioka

Reputation: 815

How to open modal after window.location.reload()

I have code like this :

$("#savedata").submit(function(e){
e.preventDefault();
$.ajax({
    type : 'POST',
    data: $("#savedata").serialize(),
    url : "<?php echo site_url('ppdb/simpan_data/'.$jenjang);?>",
    success : function(data){
        window.location.reload();
        $('#cekulang').modal('show');
    }
});
return false;
});

I want to open the modal after page done refreshing. but i got the modal open first then the page refreshing with that code.

Help is appreciated.

Upvotes: 1

Views: 17329

Answers (1)

John Pangilinan
John Pangilinan

Reputation: 1031

Try something like:

success: function(data){
    window.location = window.location.href + "?openmodal=1";
}

And add in your body

<?php
    if($_GET['openmodal'] == 1){ ?>
        <script>
                 $(function(){
                     $('#cekulang').modal('show');
                 });
        </script>
<?php         
    }
?>

Upvotes: 7

Related Questions