How to react on connection refused errors on AJAX requests?

How to react on connection refused errors on AJAX requests?

Hallo,

how can one react on connection refused errors when doing an ajax request with $.ajax()? I installed an error handler which should retry (after a certain timeout) to connect to a backend server by calling $.ajax(this);, but this error handler only works if there was any HTTP error, but not on "deeper" network errors like connection refused if the server went offline in meantime.
I'm looking for a way to retry to connect to the server e.g. each second until the connection is established again. Is there a way to achieve this with jQuery or by using XMLHttpRequest directly?

Thanks for your answers,
crispinus