dongyu9894 2019-01-11 04:54
浏览 47

计数器设置为0后执行ajax

I am creating a PPC site. When timer counter is set to 0 code should automatically run query. If user close window and click again query should not trigger until again 30 secs are completed.

URL is set in database for users to visit with a column of hits. If hits are set to 0 or 1 by default (0) it will show. when a page is run it fetch record. Set two session of current URL & previous URL and update hits to 1. Both session are set similar initially. after thirty seconds when page loads again first current URL session is created ant it matches both session. If both session are different it will update hits to 2 by matching previous URL session and login ID.

Creating sessions of current URL and previous URL

$_SESSION['url']=$row['url'];
$_SESSION['previousURL']=$row['url'];

Javascript is used for timer

<script language="JavaScript" type="text/javascript"> 
function checklength(i) {
    'use strict';
    if (i < 10) {
        i = "0" + i;
    }
    return i;
}

var minutes, seconds, count, counter, timer;
count = 30; //seconds
counter = setInterval(timer, 1000);

function timer() {
    'use strict';
    count = count - 1;
    minutes = checklength(Math.floor(count / 60));
    seconds = checklength(count - minutes * 60);
    if (count < 0) {

        clearInterval(counter);
        return;
    }
    document.getElementById("countdown").innerHTML = 'Next refresh in ' + minutes + ':' + seconds + ' ';
    if (count === 0) {

        location.reload();
    }
}
    </script> 

Actual output what i am getting in this case is if timer wont complete and user close window than by clicking again it fetch previous URL and set hits to 2.

What expected is that update query should only trigger when timer gets completed.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?