I am developing an Android phonegap application. When I launch the application without an Internet connection, it is forcibly closed. I need to check internet connection in dom before calling ajax using jquery / javascript
Here is my sample code:
var a=navigator.onLine; if(a){ alert('online'); $.ajax({ type: "GET", url: url, dataType: 'json', async: true, cache: false, success: function(data){ alert('success'); }, error: function(e){ alert('error'); } }); }else{ alert('ofline'); }
But I always get a warning ("online"), even if there is no internet connection. Please kindly guide me. Thanks at Advance
source share