HTML
<li><a class="download-link" href="<?php echo $path_data;?>">Download</a></li>
AJAX
$(function(){
$('.download-link').click(function() {
var wall_id = <?php echo $wall_id;?>; //store current wall id
$.ajax({
type : 'GET',
url : 'functionality/php/download_count.php',
data : { wall_id : wall_id }
}); //ajax end
}); //live end
}); //function end
php(download_count.php
)
<?php
$wall_id = preg_replace("#[^0-9]#", "", $_GET['wall_id']);
//increment download count query
$increment_downloads = $connectDB->prepare("UPDATE database.table SET
downloads = downloads + 1 WHERE wall_id = ?");
$increment_downloads->bind_param('i', $wall_id);
$increment_downloads->execute();
?>
点击download count
链接时,我尝试更新Download
。但是表格中的下载量不会增加。不确定问题出在哪里。需要帮助。
更新:以上代码无法在Firefox和Safari中使用,但适用于Chrome。
答案 0 :(得分:0)
您在var wall_id
var wall_id = <?php echo $wall_id;?>;
应该是
var wall_id = "<?php echo $wall_id;?>";
答案 1 :(得分:0)
更改你的ajax
$('.download-link').click(function(){
var wall_id = <?php echo $wall_id;?>; //store current wall id
$.ajax({
type : 'GET',
url : 'functionality/php/download_count.php',
data : { wall_id : wall_id }
}); //ajax end
});
到
$.get( "functionality/php/download_count.php", { wall_id : wall_id } )
.done(function( data ) {
alert( data );
});
然后将此添加到PHP脚本的末尾
echo $_GET['wall_id'];
然后告诉我你是否得到了正确的价值