Reconnect (ajax)

Reconnect (ajax)

The question is about ajax. How to reconnect if Internet connection is lost?

Is this code is corrent? (I use timeout becouse there is no way to find out Internet connection problem.)

  1. $.ajaxSetup({
  2.       timeout : 30000
  3. });
  4. $.ajax().fail(function(error) {
  5.       if(error === "timeout") {
  6.             $.ajax();
  7.       }
  8. });