最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Dialog box if there is no internet connection using jquery or ajax - Stack Overflow

programmeradmin0浏览0评论

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
Add a comment  | 

2 Answers 2

Reset to default 13

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

function isOnline() {
    var online = navigator.onLine;    // Detecting the internet connection
    if(online) {
       // do your stuff
    } else {
       alert('You\'re Offline now...');
    }
}
发布评论

评论列表(0)

  1. 暂无评论