If there is no internet connection ,it will show some error message using dialog box like " No internet connection" without using java .I need to display using jquery or ajax script alert...
If there is no internet connection ,it will show some error message using dialog box like " No internet connection" without using java .I need to display using jquery or ajax script alert...
Share Improve this question edited Apr 5, 2012 at 9:43 Raj asked Apr 5, 2012 at 9:38 RajRaj 1931 gold badge3 silver badges13 bronze badges 2- 1 Possible duplicate stackoverflow.com/questions/189430/… – Akhil Thayyil Commented Apr 5, 2012 at 9:43
- i need to show some dialog box in my mobile app if there is no internet connection.dont bother about button...if i am in offline – Raj Commented Apr 5, 2012 at 9:45
2 Answers
Reset to default 13In your JQuery ajax call, you could use the following and then query the status code of the error. Note that the status code will be 0 if they are offline, but you can also query other status codes (see below for a list):
$.ajax({
//your ajax options
error: function(statusCode, errorThrown) {
if (statusCode.status == 0) {
alert("you're offline");
}
}
});
Here's a list of status codes you could also catch for reference: http://support.google.com/webmasters/bin/answer.py?hl=en&answer=40132
function isOnline() {
var online = navigator.onLine; // Detecting the internet connection
if(online) {
// do your stuff
} else {
alert('You\'re Offline now...');
}
}