Check Internet connectivity with jquery

前端 未结 7 797
无人及你
无人及你 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:20

    you cannot get simple true or false in return, give them a callback handler

    function is_internet_connected(callbackhandler)
    {
    $.get({
      url: "/app/check_connectivity/",
      success: function(){
         callbackhandler(true);
      },
      error: function(){
         callbackhandler(false);
      },
      dataType: 'text'
    });
    }
    

提交回复
热议问题