开发者

Disconnect a jquery connection after an inactivity period

I'm using TCP keepalive on the server side to keep the connection alive, and notify the server if the client dies. How can I configure jQuery.get() to disconnect the connection after a certain period of idle time?

Edit - I would like to consider "idle time" as time where no TCP packets are exchanged. Since the Server has TCP keepalive, it will constantly send 0-data packets to the client.

@J-P's 开发者_运维知识库answer is not an exact match for what I want. If the connection is open, has keep-alive traffic but no data, I would like to keep it open indefinitely.


Use the timeout option:

jQuery.ajax({
    url: '...',
    timeout: 3000,
    success: function(){ /*...*/ }
});

Or, if you want the same timeout for all requests:

$.ajaxSetup({
    timeout: 3000
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜