I am developing android phonegap application.When i run the application without internet connection,it is force closed.so,I need to check the internet connection in the dom,before calling the 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 Am always getting the alert('online'),even when there is no internet connection.Please kindly guide me.Thanks in Advance