gpt4 book ai didi

java - 如何使用 JavaScript、jQuery 和 HTML 为所有登录用户刷新页面(协作编辑)?

转载 作者:行者123 更新时间:2023-12-02 08:30:45 25 4
gpt4 key购买 nike

我希望该操作自动反射(reflect)给所有登录的用户。

最佳答案

您可能想使用XMLHttpRequest每隔几秒左右轮询一次服务器。然后,服务器可以近乎实时地向访问您网站的所有用户(或选定的少数用户)的浏览器发出指令响应。

您可能还想考虑long polling而不是上述,在不增加轮询频率的情况下减少延迟。

引用Comet Daily: The Long-Polling Technique :

The long-polling Comet technique is a technique that optimizes traditional polling to reduce latency.

Traditional polling sends an XMLHttpRequest to the server in fixed intervals. For example, open a new XMLHttpRequest every 15 seconds, receive an immediate response, and close the connection.

Long-polling sends a request to the server, but a response is not returned to the client until one is available. As soon as the connection is closed, either due to a response being received by the client or if a request times out, a new connection is initiated. The result is a significant reduction in latency because the server usually has a connection established when it is ready to return information to return to the client.

除了上述内容之外,我还建议您查看以下 Stack Overflow 帖子的已接受答案,以获取长轮询技术的详细说明:

关于java - 如何使用 JavaScript、jQuery 和 HTML 为所有登录用户刷新页面(协作编辑)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3432342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com