title: How to alert the user when there's no internet connection
body: <p>I need to alert the user with the following conditions;</p>
  
  <ol>
  <li>Request timed out</li>
  <li>No internet connection</li>
  <li>Unable to reach the server</li>
  </ol>
  
  <p>Here's the code; How to capture the following conditions when occurred and alert the user ?</p>
  
  <pre><code>failure: function (response) {
      var text = response.responseText;
      console.log("FAILED");
  },success: function (response) {
      var text = response.responseText;
      console.log("SUCCESS");
  }
  </code></pre>
  
  <p>I tried the following code to check if the internet is reachable, but it didn't work</p>
  
  <pre><code>var networkState = navigator.network.connection.type
      alert(states[networkState]);
      if (networkState == Connection.NONE){
          alert('No internet ');
      };
  </code></pre>
  
  <p><strong>UPDATE **</strong></p>
  
  <p>I added the following in my index.html, but, when i disable WIFI, i don't see the alert popping. </p>
  
  <pre><code>&lt;script&gt;
  function onDeviceReady() {
      document.addEventListener("offline", function() {
          alert("No internet connection");
      }, false);
  }
  &lt;/script&gt;
  </code></pre>