ripper234
ripper234

Reputation: 230058

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.

Upvotes: 2

Views: 699

Answers (1)

James
James

Reputation: 111930

Use the timeout option:

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

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

$.ajaxSetup({
    timeout: 3000
});

Upvotes: 1

Related Questions