I’m trying to send an ajax call (for logging purposes) just before I redirect. Actually, the redirect is a download that has octet-stream and disposition set up properly. So the ajax call does not gets called on all browsers (particularly chrome). In others like IE it does. How can I make sure the call gets executed for SURE?
this is the code:
$(function() {
$('#download-link-a').click(function() {
remoteLog ('Clicked on download', '<?php echo $username; ?>' );
location.href = "<?php echo $secure_link; ?>";
return false;
});
});
function remoteLog (arg, key) {
var file = '/files/remoteLog.php';
$.post(file, {text: arg, key: key});
}
You need to use a callback function to invoke the redirect only after a successful
POST. I suggest that you use$.ajax()instead of$.post()because it’s more customizable.Here’s how you can turn your
$.post()into an$.ajax()equivalent with the appropriate callback functions:More reading: jQuery.ajax()