每点击一次静态页面刷新,点击率增加1,这需要在静态页面中加入一段juqery代码,我是这样写的:<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
$(function(){
var date="action=update&ids="+<%$id%>;
var url="../test.php";
$.post(url,date,function(result){
$('#hits').text('result');
});
});
</script>
</head><body>
<div>点击:<span id="hits"></span></div>
</body>
然后在test.php文件中写的是:if($_POST['action'] && $_POST['action']<>''){
$ids=$_GET['ids'];
$upsql="update `file` set `hits`=hits+1 where id=".$ids;
$db->getRow($upsql);
$sesql="select `hits` from `file` where `id`=".$ids;
$result=$db->getRow($sesql);
}怎么点击率不变呀? 麻烦给我修改一下,或者给出新的编写代码,使点击率能更新
<script type="text/javascript">
$(function(){
var date="action=update&ids="+<%$id%>;
var url="../test.php";
$.post(url,date,function(result){
$('#hits').text('result');
});
});
</script>
</head><body>
<div>点击:<span id="hits"></span></div>
</body>
然后在test.php文件中写的是:if($_POST['action'] && $_POST['action']<>''){
$ids=$_GET['ids'];
$upsql="update `file` set `hits`=hits+1 where id=".$ids;
$db->getRow($upsql);
$sesql="select `hits` from `file` where `id`=".$ids;
$result=$db->getRow($sesql);
}怎么点击率不变呀? 麻烦给我修改一下,或者给出新的编写代码,使点击率能更新
<script type="text/javascript" src="../js/jquery.js"></script>
</head><body>
<div>点击:<span id="hits"></span></div>
<script type="text/javascript">
$(function(){
var date="action=update&ids="+<%$id%>;
var url="../test.php";
$.post(url,date,function(result){
$('#hits').text('result'); //result多了引号$('#hits').text(result);
});
});
$()不知道是什么意思,是load后,还是即使的,如果是即使的就应该在<span id="hits"></span>下面
</script>
</body>另外,ajax默认的提交方式是get还是post,检查一下数据是否能接收到
另外,我觉得应该叫点击量更合适,点击率应该表示的是一个点击比例,比如我的网站今天一共有1000个pv,其中某一个链接的pv次数是100,那这个链接的点击率就是10%
不好意思,result加引号是我调试的时候加的,这里忘了去掉了,不过去掉引号也不对
因为我这里用的是$.post 所有php文件里也是用$_POST接收