Realitme via ajax,如何创建与龙卷风等非阻塞服务器的开放连接?
当人们创建实时 Web 应用程序时,他们会将 ajax 请求保持打开/长时间运行。
他们如何在 JavaScript 中做到这一点?
When people create real-time web apps, they are leaving a ajax request open/long running.
how do they do this in javascript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
和普通的ajax请求其实没有什么区别。回调与 XMLHttpRequest 关联。请求完成后,将调用回调。不同之处在于服务器端请求保持打开状态,直到数据准备好供客户端使用或发生超时。在浏览器端,当每个连续请求得到应答时,都会调用回调。回调必须处理来自服务器的数据并发起另一个请求。该请求是异步处理的,因此浏览器不会被阻止。
整个事情的一个很好的例子是聊天演示< a href="http://www.tornadoweb.org/" rel="nofollow">龙卷风。
There is really no difference from a normal ajax request. A callback is associated with the XMLHttpRequest. Once the request is complete the callback is invoked. The difference is on the server-side where the request is held open until data is ready for the client, or a timeout occurs. On the browser side, the callback is invoked as each successive request is answered. The callback must process the data from the server and initiate another request. The request is handled asynchronously, so the browser is not blocked.
A really good example of the whole thing is the chat demo included in Tornado.