【发布时间】:2015-12-11 13:38:50
【问题描述】:
我正在 AJAX 中创建简单的文件下载计数器。但在我的代码中,计数器在 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 代码中的数据库或下载计数器没有任何问题。我在下载文件时遇到问题。计数器加一,但文件未下载。
【问题讨论】:
-
您必须在
click事件处理程序中将return false;替换为return true;。 -
谢谢@mapek...!它现在工作
-
太棒了!我已将其添加为答案并链接到另一个问题的有用答案。