Question

In my ASP.NET application, I am having the form with different controls and after filling the form, when I click the save button, If the server connection is available, the datas has to be saved directly to the Sql Server and if the connectivity is not available, the datas has to be saved to my local IndexedDB Datatbase. And later, if the connectivity becomes available, the IndexedDB datas should be saved to the Sql Server and the IndexedDB datas should be deleted upon successful insertion of datas in my Sql Server. I want to know how to check whether the connectivity is available or not???

Was it helpful?

Solution

You can use navigator.onLine to check if you are online.

window.addEventListener('load', function () {
  function onlineStatusChanged(event) {
    alert( 'Now ' + navigator.onLine ? "online" : "offline" );
  }
  window.addEventListener('online', onlineStatusChanged);
  window.addEventListener('offline', onlineStatusChanged);
});

Keep in mind that this is not always guaranteed to be correct.

OTHER TIPS

You can use Ajax to check response...Use XMLHTTPREQUEST Object.Explore this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top