不使用 IFrame 的 Comet 应用程序

发布于 2024-07-09 08:32:26 字数 183 浏览 5 评论 0原文

我刚刚开始使用服务器端推送创建 AJAX 应用程序。 我在 Glassfish V2 上使用 Grizzly Comet。 几乎所有示例应用程序都使用 IFrame 来更新客户端内容。 我想坚持使用仅 JavaScript。 是否有任何此类示例应用程序(最好是不使用 JavaScript 库的示例应用程序)?

I am just getting started creating an AJAX application using server side push. I am using Grizzly Comet on Glassfish V2. Almost all the sample applications use IFrames for updating content on the client side. I want to stick to using JavaScript only. Are there any such sample applications (preferably ones that do not use a JavaScript library)?

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

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

发布评论

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

评论(2

童话里做英雄 2024-07-16 08:32:26

关于推送的要点是 HTTP 请求永远不会结束。 并非所有客户端实现都能正确处理该问题。 在我看来,可以在 Firefox 中使用纯 JavaScript 及其广泛的 API 来完成此操作,但 XMLHTTPRequest 对象会超时并且无法向您传输内容。

IFrame 很好,如果涉及标准合规性,您也可以尝试对象标记。

在 XMLHTTPRequest 和 Ajax 还没有名字之前,我们曾经通过 IFrame 从服务器获取数据。

The point about the push is that the HTTP request never ends. Not all client implementations handle that correctly. As I see it, it's possible to do it with pure javascript in Firefox with its extensive API, but the XMLHTTPRequest object would timeout and would not be able to stream you the content.

IFrame is good, you could also try the object tag if its about standard compliance.

Before XMLHTTPRequest and Ajax had no name, we used to get data from the servers through IFrames.

时光礼记 2024-07-16 08:32:26

这就是我如何弄清楚如何仅使用 javascript 和 php 进行推送。

让 javascript 进行初始调用并将内容加载到 div 中。
然后让 javascript 回调到 php 并让 php 休眠,直到它看到有新的更新。
然后把数据发送给大家,回调到php再sleep。

这允许长时间轮询和更少的连续调用。 我个人在php脚本上设定的时间为5分钟到30分钟。

This is how I figured out how to do a push with just javascript and php.

Have javascript do an initial call and load content into a div.
Then have the javascript call back to the php and have the php sleep until it see there is a new update.
Then send out the data to everyone and call back to php and sleep again.

This allows for long polling and fewer calls back to back. I personally put a time of 5 mins to 30 mins on the php script.

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