JSP定时器重置问题

发布于 2024-10-09 01:18:38 字数 100 浏览 0 评论 0原文

我创建了一个在线测验,用户必须在规定的时间内完成测试。我找到了一个计时器的javascript代码。它有效,但是当我提交一个问题并转到下一个问题时,计时器会重置。知道如何解决这个问题吗?

I created an online quiz, users have to finish the test within the time. I found a timer javascript code. It works, but when i submit one question and go to next question the timer reset. Any idea how i can solve this problem?

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

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

发布评论

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

评论(2

你不是我要的菜∠ 2024-10-16 01:18:38

您需要管理服务器端会话上的计时器。因此,当用户开始测试时,

  1. 在服务器上创建一个会话
  2. ,将计时器附加到每个问题的会话,
  3. 提交检查计时器

You need to manage the timer on server side session. So, when the user starts a test

  1. create a session on the server
  2. attach timer to the session
  3. for each question submit check the timer
黑白记忆 2024-10-16 01:18:38

问题在于,当浏览器收到 html 代码时,就会执行 javascript 代码,因此当它“离开”页面并加载另一个页面时(例如,当您提交表单或按链接时),您会得到另一个 javascript 代码,你就会失去那个计时器。

如果你无法像 Pangea 所说的那样在服务器端管理计时器,你可以尝试使用 ajax 加载所有内容。我的意思是,当您启动计时器时,您有第一个 jsp,并且您有一个容器,并且通过 ajax 调用您可以更新该容器的内容并将数据发送到服务器。只要您不“离开”页面,计时器就会保持不变。

The problem is that the javascript code is executed when the html code is received by the browser, so when it "leaves" the page and load another one (for example when you submit a form or you press a link) you have another javascript code, and you'll lose that timer.

If you cannot manage the timer in the server side as Pangea says you can try to load all the content with ajax. I mean, you have a first jsp when you start the timer and you have for example a container and with ajax calls you update the contents of this container and send data tothe server. The timer will be the same as long as you don't "leave" the page.

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