ajax 和本地/会话存储模式

发布于 2024-12-17 08:55:19 字数 412 浏览 1 评论 0原文

我正在构建一个使用 ajax 与服务器通信的网络应用程序。基本上,用户请求一条记录,它以 json 形式返回,它被添加到 DOM 中,然后用户对其进行更改。当用户请求下一条记录时,当前记录被字符串化并发回服务器,并返回下一条记录。

所有这些都非常有效......只要用户不断请求记录。但是,我想知道如何处理用户停止工作的情况:如何更新最后一条记录?

我想到在他编辑工作记录时将工作记录添加到本地存储中,并且在每次编辑时更新本地存储,如果他下次登录并且那里仍然有记录,则在他登录时使用ajax它。他的方法的问题在于,如果另一个用户登录到同一台计算机,那么当该新用户登录时,他正在更新另一个用户的数据。

我也想过使用 window.unload 事件;但这并不能解决用户在最终更新之前关闭浏览器的问题。

有哪些好的方法可以处理这个问题。感谢您的建议。

I'm building a web app that uses ajax to communicate with the server. Basically, the user requests a record, it comes back in json, it's added to the DOM and the user makes changes to it. When the user requests the next record, the current record is stringified and sent back to the server and the following record comes back.

All this works really well.... as long as the user keeps requesting records. However, I am wondering how to handle the situation where the user stops his work: how do I get the last record updated?

I thought of adding the working record to the local storage while he's editing it and at each edit, updating the local storage and if he logs on next time and there's still a record in there, ajax it when he logs on. The problem with his approach is that if another user logs on to the same computer, then when that new user logs on, he's updating the data of another user.

I thought of using the window.unload event also; but that doesn't solve the problem of the user closing his browser before the final update.

What are some good ways to handle this issue. Thanks for your suggestions.

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

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

发布评论

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

评论(2

长安忆 2024-12-24 08:55:19

我会考虑“类似草稿”的功能。您可以在一定时间没有输入后上传更改,例如,15 秒没有输入后,推送这些更改。

I would consider a 'draft-like' feature. Where you could upload changes after a certain amount of time of no input, for instance, after 15 seconds of no input, push those changes.

影子的影子 2024-12-24 08:55:19

如果您的应用需要登录,您可以使用 localStorage 的 ID 进行键入,如下所示:

localStorage.getItem( "user13434" )

将检索 user13434 的数据

localStorage.getItem( "user12345" )

将检索 user12345 的数据

如果信息敏感但不太敏感,您可以添加加密,但经验丰富的用户可以解密,这就是为什么它必须不要太敏感。

If your app requires login, you could key the localStorage using their ids like so:

localStorage.getItem( "user13434" )

would retrieve data for user13434

localStorage.getItem( "user12345" )

would retrieve data for user12345

If the information is sensitive but not too sensitive you could add encryption, but it can be decrypted by experienced users which is why it must not be too sensitive.

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