[英]File downloading in AJAX with download counter
我正在AJAX中创建简单的文件下载计数器。 但是在我的代码中,counter正在PHP代码中工作,意味着它的值每次下载增加了一个,但文件未下载。 下面是我的代码
的index.php
<script type="text/javascript">
$(function() {
$(".download_button").click(function() {
var test = $("#content").val();
var dataString = 'content='+ test;
$.ajax({
type: "POST",
url: "download_counter.php",
data: dataString,
cache: false,
success: function(html){
$("#display").after(html);
}
});
return false;
});
});
</script>
<a href="file_path/file.pdf" class="download_button" id="v" download>
Download
</a>
download_counter.php
<?php
//Code for counter Increment
//Query to Update database
?>
我对数据库或PHP代码中的下载计数器没有任何问题。 我在下载文件时遇到问题。 计数器增加一,但文件未下载。
您必须替换return false;
return true;
在onclick事件处理程序中,以便将执行超链接的默认事件。
请检查此答案以获取有关return false;
更多信息return false;
在事件处理程序中: https : //stackoverflow.com/a/11184286/3647441
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.