js判断网络连通性

js判断网络连通性
if (window.navigator.onLine == true) {
                        console.log("首次 -- 已连接")
                        $.ajax({
                            url: "https://www.baidu.com/",
                            type: "POST",
                            timeout: 1000,
                            dataType: "json",
                        }).complete(function (XMLHttpRequest) {
                            console.log(XMLHttpRequest);
                            if (XMLHttpRequest.status == 200) {
                                $notification.show("已经可以正常上网", !0);
                            } else {
                                console.log("准备打开上网认证界面");
                                window.open(e, i);
                            }
                        });
                    } else {
                        $notification.show("网络未连接--请检查网络");
                    }
posted @ 2018-04-12 11:55  乾源  阅读(1086)  评论(0编辑  收藏  举报