简体   繁体   English

什么是AJAX HeartBeat,它与setInterval有什么区别

[英]What is AJAX HeartBeat and what is the difference between it and setInterval

I want to know what is exactly AJAX heartbeat pattern and what is the difference between it and jquery setInterval 我想知道什么是AJAX心跳模式,它与jquery setInterval有什么区别

Because im making an AJAX chat and I don't want to pull the data every 15 seconds I want to make a connection to the server to avoid delay is that what called heartbeat ? 因为我正在进行AJAX聊天,并且我不想每15秒提取一次数据,所以我想与服务器建立连接以避免延迟,这就是所谓的心跳吗? Also I want a good tutorial to make this or any suggestion from you 我也想要一个好的教程来提出这个建议或您的任何建议

Note: I have completed the implementation with setInterval but I saw that heartbeat is better way to avoid delay 注意:我已经用setInterval完成了实现,但是我发现心跳是避免延迟的更好方法

Heartbeat is a design pattern, this means it's a way of coding solutions. 心跳是一种设计模式,这意味着它是一种编码解决方案的方式。

Here a technique is meant, where you keep sending requests to the server, so the server knows the user/browser is still present. 这里的技术是指,您不断向服务器发送请求,以便服务器知道用户/浏览器仍然存在。 There are several use-cases for this pattern, for example to prevent timeouts of sessions etc. 此模式有多个用例,例如,防止会话超时等。

You cannot really compare a design pattern to a function, because setInterval could be used to implement this pattern. 您不能真正将设计模式与功能进行比较,因为setInterval可用于实现此模式。 You would keep sending request in a specified interval. 您将在指定的时间间隔内继续发送请求。

I don't have a tutorial at hand, but the first hits on google already contain some examples. 我手头没有教程,但是google的第一批热门文章已经包含了一些示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM