In my WordPress project, my Download button containing a .zip
file, which onClick should be downloaded. So the HTML producing is:
<a id="732" class="btn btn-default download-link" href="https://example.com/download.zip">DOWNLOAD</a>
I'm using AJAX to refresh the download count.
<script type="text/javascript">
var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
jQuery(document).on('click', '.download-link', function () {
var id = this.id;
jQuery.ajax({
type: 'POST',
url: ajaxurl,
data: {"action": "count_download",
"id": id
},
success: function (data) {
window.location = site.url + "/download-success?fid="+ id;
}
});
});
</script>
Everything works fine until I added the file with the link. Typically such a link will start downloading the .zip
file, but even after the time taken by the AJAX call the page redirected to the download-success page without triggering the download.
And it occurs most of the time, only once or twice the file starts downloading.
P.S.: I tested this but it's not my case.