当用户单击下载链接时,我有一个下载链接,计数器应使用php通过ajax存储在数据库表中。我已经尝试使用以下代码。这是正确的存储方式,还是我们需要增加php文件中的计数。
$('#doc_attachment').click(function(){
init_count++;
$.ajax({
url:'<?php echo $block->getUrl("orderattachments/customer/doccount") ?>',
type:'POST',
data:"&initial_count="+init_count+'&',
dataType:'json',
success:function(response){
console.log("tse");
},
error:function(request, status, error){
console.log(request.responseText);
}
})
})
error:function(request, status, error){
console.log(request.responseText);
}
})
})
答案 0 :(得分:0)
希望doccount
是一项PHP
函数,用于更新计数。如果是这样,您可以尝试以下查询:
UPDATE countertable
SET counter = counter + 1
WHERE counterid = <ID_related_to_downloading_doc>