how does long polling work javascript?

前端 未结 7 1213
傲寒
傲寒 2020-12-08 11:41

Hi I understand that in long polling you keep the connection with the server open for long till you a get a response back from the server and then poll again and wait for th

相关标签:
7条回答
  • 2020-12-08 12:09

    I guess no one properly explain why do we need timeout in the code. From jQuery Ajax docs:

    Set a timeout (in milliseconds) for the request. This will override any global timeout set with $.ajaxSetup(). The timeout period starts at the point the $.ajax call is made; if several other requests are in progress and the browser has no connections available, it is possible for a request to time out before it can be sent

    The timeout option indeed doesn't delay the next execution for X seconds. it only sets a maximum timeout for the current call. Good article about timeout stuff - https://mashupweb.wordpress.com/2013/06/26/you-should-always-add-timeout-to-you-ajax-call-in-jquery/

    0 讨论(0)
提交回复
热议问题