views:

41

answers:

1

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.

+1  A: 

Use the timeout option:

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

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

$.ajaxSetup({
    timeout: 3000
});
J-P
Not exactly what I'm after (see edited question).
ripper234