Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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...

like image 608
Raj Avatar asked Apr 05 '12 09:04

Raj


People also ask

Does Ajax require Internet?

Since the Ajax applications communicate with the Hub via the server, you cannot operate the Hub via applications in the case of Internet connection failure.

Can Ajax be used with jQuery?

jQuery provides several methods for AJAX functionality. With the jQuery AJAX methods, you can request text, HTML, XML, or JSON from a remote server using both HTTP Get and HTTP Post - And you can load the external data directly into the selected HTML elements of your web page!

Does jQuery require Internet?

No you do not need the internet connection when writing codes in jQuery. Download the jQuery file, keep it on the website folder and then include it on your page. In case if you are putting the jQuery CDN link in your website only then you will need internet connection.


1 Answers

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

like image 61
mattytommo Avatar answered Oct 26 '22 14:10

mattytommo