Javascript 中的会话值

发布于 2024-09-17 01:14:09 字数 31 浏览 2 评论 0原文

如何在 JavaScript 中读取和写入会话值

How to read and write session values in javascript

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

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

发布评论

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

评论(7

英雄似剑 2024-09-24 01:14:09

如果您谈到服务器端会话值,除了以某种方式与服务器通信之外没有其他方法(例如,使用异步回调,您可以使用某种方法读取/写入它们)。

对于客户端会话变量的模拟,您可能需要查看此处;)

If you speak about server-side session values, there's no other way than to somehow communicate with the server (e.g. with an asynchronous callback where you would read/write them with some method).

For simulation of client-side session variables, you might want to have a look here ;)

尽揽少女心 2024-09-24 01:14:09

您不能使用 JavaScript 直接写入服务器端会话变量。假设您这里没有使用 Ajax。

you can't write directly to a server side session var with javascript. Assuming you are not using Ajax here.

小情绪 2024-09-24 01:14:09

会话变量驻留在服务器上,我相信您知道,Javascript 是客户端。

Session variables reside on the server and as I'm sure you are aware, Javascript is client-side.

财迷小姐 2024-09-24 01:14:09

更多的背景信息可能有助于理解您到底想要实现什么目标。由于会话是在服务器上进行的,因此与其“即时”通信的唯一方法是使用 AJAX 调用。

这不是一种常见的操作方式,也许解释您的情况可能有助于为您提供替代的、更常见的方式来完成您需要的操作。

A bit more context could be useful in understanding what exactly you're trying to achieve. As the session is held on the server, the only way to "instantly" communicate with it would be using AJAX calls.

This being not such a common way of operating maybe explaining your situation may help in giving you alternative, more common ways of doing what you need.

暮年 2024-09-24 01:14:09

HTTP 会话变量由服务器控制,
JavaScript 在客户端运行,因此无法直接修改变量。
这意味着仅使用 Javascript 是不可能的

HTTP session vars are controlled by the server,
JavaScript runs client side, and as such cannot modify the vars directly.
Meaning this isn't possible using only Javascript

征﹌骨岁月お 2024-09-24 01:14:09

Java 是客户端脚本语言。客户端的网络浏览器对会话一无所知!

您所能做的就是使用 cookie 来存储可跨网页访问的值。

Java is client side scripting language. The client's web-browser does not know anything about session!

All you can do is to use cookies to store values which can be accessed across web-pages.

套路撩心 2024-09-24 01:14:09

你不能,因为会话变量实际上只保存到服务器上的文件中。您的浏览器唯一知道的有关会话的信息是会话 ID,它保存在 cookie 中。

这就是会议的全部意义所在。这些变量是安全的,因为外部没有人可以读取它们。如果您希望浏览器可以读取变量,请考虑使用 cookie。

You can't because session variables are actually saved to a file on the server only. The only thing your browser knows about the session is the session id, which is saved into a cookie.

This is the whole point with sessions. The variables are safe because no one on the outside can read them. If you want variables readable by the browser, consider using cookies instead.

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