使用Ajax将数据从服务器发送到客户端 [英] Sending data from server to clients using ajax

查看:249
本文介绍了使用Ajax将数据从服务器发送到客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个场景.我正在制作一个基于Intranet的Web应用程序供公司内部使用. 在这种情况下,只要一个客户端更新了应用程序中的任何内容,另一个客户端就应该更新.

I have a scenario. i m making a intranet based web application for internal company use. In which whenever a client updates anything in application.. the other client should be updated .

步骤:

  1. 一个客户端更新了一些任务.

  1. One Client update some task .

然后服务器自动将更新的数据发送到当前连接的客户端.

Then server automatically send the updated data to currently connected clients.

因此,客户端可以更新,而无需向服务器发送请求并时不时检查更改.

Hence the client gets updated without sending request to server and checking the changes every now and then.

请大家给我一些建议,以实现这一目标.任何指针,评论都将非常有帮助. 谢谢

Please guys give me suggestions how to achieve this.. Any pointer , comments will be really helpful . Thanks

推荐答案

您正在寻找的被称为

What you are looking for is called Comet. The basic idea is the following: when the client makes a request, the server keeps the HTTP connection open for a while and only replies when

  • 或者有一些更新
  • 或经过固定时间(例如一分钟)

当客户端收到更新时,它会处理新数据(如果有)并立即请求其他更新,并且循环继续进行.例如,这是通过HTTP进行的流行聊天所使用的方法.您可以在上面的链接中找到更多详细信息.

When the client receives the update, it processes the new data (if any) and immediately asks for another update, and the cycle continues. This is the method used by popular chats over HTTP for instance. You can find more details exploring the above link.

这篇关于使用Ajax将数据从服务器发送到客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆