Dialog box if there is no internet connection using jquery or ajax

If there is no internet connection, it will display some error message using the "No Internet connection" dialog box without using java. I need to display using jquery or ajax script alert ...

+8
javascript jquery ajax internet-connection dialog
source share
2 answers

In your jQuery ajax call, you can use the following and then request the error status code. Please note that the status code will be 0 if they are offline, but you can also request other status codes (see the list below):

$.ajax({ //your ajax options error: function(statusCode, errorThrown) { if (statusCode.status == 0) { alert("you're offline"); } } }); 

Here is a list of status codes you can also get for the link: http://support.google.com/webmasters/bin/answer.py?hl=en&answer=40132

+13
source share
 function isOnline() { var online = navigator.onLine; // Detecting the internet connection if(online) { // do your stuff } else { alert('You\'re Offline now...'); } } 
+4
source share

All Articles