Check Internet connectivity with jquery

前端 未结 7 788
无人及你
无人及你 2020-12-05 20:29

I am trying to check for the internet connection by sending a GET request to the server. I am a beginner in jquery and javascript. I am not using navigator.onLine

7条回答
  •  甜味超标
    2020-12-05 21:07

    Do you mean to check the internet connection if it's connected?

    If so, try this:

    $.ajax({
        url: "url.php",
        timeout: 10000,
        error: function(jqXHR) { 
            if(jqXHR.status==0) {
                alert(" fail to connect, please check your connection settings");
            }
        },
        success: function() {
            alert(" your connection is alright!");
        }
    });
    

提交回复
热议问题