非 JavaScript 定时器

发布于 2024-09-14 22:08:06 字数 173 浏览 3 评论 0原文

嘿伙计们,我正在做一个有限制的测验,我想用 javascript 以外的东西来跟踪剩余的时间,因为使用 javascript,用户可以通过禁用 javascript 来简单地暂停计时器,并根据需要花费尽可能多的时间。当他们完成后,他们可以简单地重新打开 JS 并提交测验。我正在使用 Coldfusion,如果这有帮助,请提前致谢。

Hey guys, I'm making a quiz with a limit, I want to keep track of the time left with something other than javascript, Because with javascript the user could simply pause the timer by disabling javascript, and take as much time as they need. and when they are done they could simply turn JS back on and submit the quiz. I'm using coldfusion if this helps, thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

萌无敌 2024-09-21 22:08:06

在客户端使用 javascript,在服务器端使用 会话 变量

Use javascript on the client and session variables on the server side

心欲静而疯不止 2024-09-21 22:08:06

假设您正在使用会话,我将记录用户请求页面的时间和用户提交测验的时间。我仍然会使用 JavaScript 来显示剩余时间,但仅此而已。

Assuming you are using a session, I would log the time the user requested the page and the time the user has submitted the quiz. I would still use Javascript to display them the time left, but just for that.

久光 2024-09-21 22:08:06

您应该监控用户端和服务器端。 Javascript 对于用户端来说很好,可以在时间即将耗尽时向他们发出警报,但您还应该在提交时检查服务器端。我建议在测试中附加一个隐藏字段,其中包含测试开始时间的时间戳,然后在提交时,您可以将开始时间与提交时间进行比较,以确保它们没有超过时间。 永远不要仅依赖客户端验证。

编辑
根据评论,另一种选择是让数据库保存他们的测试分数时间戳,然后在提交时服务器比较时间,如果不匹配,则什么也得不到。这完全切断了用户的注意力,包括时区,因为比较的所有内容都是由服务器根据服务器时间完成的。对于那些只想知道自己有多少时间的非邪恶用户,我仍然建议在用户端使用 javascript 跟踪时间。

You should monitor both user and server side. Javascript is fine for user side, to give them an alert when they're close to running out of time, but you should also check server side when it's submitted. I'd recommend having a hidden field attached in the test that has a timestamp of the time the test was started, then when submitted you can compare the time started to time submitted to ensure they haven't exceeded their time. Never rely on client side verification only.

Edit
Another alternative, as per the comments, would be to have the database where you keep their test scores timestamp the time they start the test, then when submitted the server compares the times and if they don't match they get nothing. This cuts the user completely out, including time zones, as everything compared is done by server time by the server. I'd still recommened tracking time with javascript on user side for those non-evil users that just want to know how much time they have.

吃兔兔 2024-09-21 22:08:06

一种方法是,假设您希望服务器在没有及时响应的情况下采取行动,则可以使用 cfthread 生成一个单独的线程,让它在测验期间休眠,并且如果他们的答案尚未得到解答,提交了,做任何事。我想象类似的事情..

  .. start of quiz stuff ..
  <cfthread action="run" name="quiztimer">
         <cfthread action="sleep" duration="120000" />
         <cfquery>fetch quiz results</cfquery>
         <cfif NoQuizAnswers>
                 <cfinsert>insert failure into quiz results</cfinsert>
         </cfif>
  </cfthread>

One approach, assuming you want your server to take action in the event that they didn't respond in time, would be to spawn a separate thread with cfthread, have it sleep the length of the quiz, and if their answers haven't been submitted, do whatever. I imagine something like..

  .. start of quiz stuff ..
  <cfthread action="run" name="quiztimer">
         <cfthread action="sleep" duration="120000" />
         <cfquery>fetch quiz results</cfquery>
         <cfif NoQuizAnswers>
                 <cfinsert>insert failure into quiz results</cfinsert>
         </cfif>
  </cfthread>
无人接听 2024-09-21 22:08:06
var oReq = getXMLHttpRequest();


function getXMLHttpRequest() {
        if (window.XMLHttpRequest) {
            return new window.XMLHttpRequest;
        }
        else {
            try {
                return new ActiveXObject("MSXML2.XMLHTTP.3.0");
            }
            catch (ex) {
                return null;
            }
        }
    }

并通过调用方法 zx 在服务器端处理此问题

function ZX(q, w, e, t) {


if (oReq != null) {
    oReq.open("GET", "XML.xml", true);
    oReq.onreadystatechange = function () {

       //work with response xml object


         alert(oReq.responseXML.getElementsByTagName("")[0].getAttribute("tag1"));
        if (oReq.readyState == 4 /* complete */) {
            if (oReq.status == 200) {
            }
        }
    };
    oReq.send();
}
else {
    window.alert("AJAX (XMLHTTP) not supported.");
}

}

var oReq = getXMLHttpRequest();


function getXMLHttpRequest() {
        if (window.XMLHttpRequest) {
            return new window.XMLHttpRequest;
        }
        else {
            try {
                return new ActiveXObject("MSXML2.XMLHTTP.3.0");
            }
            catch (ex) {
                return null;
            }
        }
    }

and handle this at server side by calling method zx

function ZX(q, w, e, t) {


if (oReq != null) {
    oReq.open("GET", "XML.xml", true);
    oReq.onreadystatechange = function () {

       //work with response xml object


         alert(oReq.responseXML.getElementsByTagName("")[0].getAttribute("tag1"));
        if (oReq.readyState == 4 /* complete */) {
            if (oReq.status == 200) {
            }
        }
    };
    oReq.send();
}
else {
    window.alert("AJAX (XMLHTTP) not supported.");
}

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文