I have one php page like this
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
window.onbeforeunload = saveBeforeExit;
function saveBeforeExit() {
jQuery.ajax({
url:"truncate_logs.php",
type:"GET",
async:false,
success:function(data){
}
})
}
</script>
//I am creating 'logs_".$t.".xls' here
<?php
header("Location: log_files/logs_".$t.".xls");
?>
My problem is here on
Location:onbeforeunload is not getting called.
I found the answer. Add async : false to your jquery ajax request.
See How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request?
onbeforeunload is not working because it isn't coded properly. You need to return a string from onbeforeunload , which will be used as the message in the window that will appear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With