我想存储价值" 20_2018" (例如)我的数据库中有一个id。我想计算每次下载的点击次数。
这就是我的尝试:
<html>
<body>
<a id="20_2018" rel="link1" href="folder.pdf">Download</a>
<script type="text/javascript">
$(document).ready(function(){
$(\'a[rel="link1"]\').click(function() {
$.ajax({
type:'POST',
url: 'send.php', // folder for sending value in id to the database
data: 'id='+$(this).attr("id"), // take the value in the id
async: false
});
return true;
});
</script>
</body>
</html>
不知何故,这不起作用。如何实现下载的点击次数?
答案 0 :(得分:0)
首先,使用<RelativeLayout....outer layout
<ScrollView....
<RelativeLayout....nested layout
Some TextViews etc...
<TableLayout.....inside nested layout/>
</RelativeLayout>
</ScrollView>
<ProgressBar....inside outer layout
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:foregroundGravity="center_vertical|center_horizontal"/>
</RelativeLayout>
阻止默认操作,然后发送您的请求。成功后,将它们带到文件URL。
preventDefault
$(document).ready(function(){
$('a[rel="link1"]').click(function(event) {
event.preventDefault();
// Gets href of the clicked anchor
var href = $(this).attr('href');
$.ajax({
type:'POST',
url: 'send.php',
data: 'id='+$(this).attr("id"),
success: function(){
// After recording click count, bring them there
location.assign(href);
},
error: function(){
alert('failed');
}
});
});
});