JSP定时器重置问题
我创建了一个在线测验,用户必须在规定的时间内完成测试。我找到了一个计时器的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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要管理服务器端会话上的计时器。因此,当用户开始测试时,
You need to manage the timer on server side session. So, when the user starts a test
问题在于,当浏览器收到 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.