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...
Dialog box if there is no internet connection using jquery or ajax
Asked Answered
Possible duplicate #189930 –
Crenate
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 –
Propylene
In 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
what is x ,e where should i apply –
Propylene
x is the HTTP Status Code of the error and e is the error object, sorry I'll update the names in my code. You should put the error inside your existing jQuery ajax call. If you post your actual code I can show you exactly where it needs to go. Take a look at the error function here: api.jquery.com/jQuery.ajax –
Haller
Status can be 0 for multiple other reasons than a network failure. –
Cowbind
0 could also mean that the firewall was blocked ( I know this from personal experience) –
Skewness
function isOnline() {
var online = navigator.onLine; // Detecting the internet connection
if(online) {
// do your stuff
} else {
alert('You\'re Offline now...');
}
}
© 2022 - 2024 — McMap. All rights reserved.