Codeigniter Javascript Alert With Success Message On Click Ok Page Refresh
I have a code like this:
×
Solution 1:
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>';
}
?>
If you want to use Bootstrap modal, try this:
<?php$message = "Your Upload was successful";
if ((isset($message)) && ($message != '')):
?><divclass="modal"id="alert-dialog"><divclass="modal-dialog"><divclass="modal-content"><divclass="modal-header"><buttontype="button"class="close"data-dismiss="modal">×</button><h4class="modal-title">Alert</h4></div><divclass="modal-body"><?phpecho$message; ?></div><divclass="modal-footer"><buttondata-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><?phpendif; ?>
Solution 2:
I'm not sure this is possible with a standard alert box, you can do it with a confirm.
e.g.
var con = confirm('Are you sure');
if (con == true) {
//means the user clicked on `OK`//refresh the page
} else {
//means the user clicked `Cancel`
}
Alternatively you could use a customized alert box, to find a suitable one just search on google.
Post a Comment for "Codeigniter Javascript Alert With Success Message On Click Ok Page Refresh"