PROBLEM
I want to show an alert if WiFi is off [i.e. no internet connection]. In my web page, I have a number of buttons, pop-ups etc. User can click anything when offline. But I want to show if there is a failure in API call. I can check navigator.onLine
in each click. But I dont want to write number of function calls or lines. Is there any way to do it commonly using jQuery, JS, Ajax?
"ALERT should be shown when call fails which caused by an user action"
Like $.ajax
with error. It shouldn't be bounded with any div/page.
Hi, I have tried the following:
navigator.onLine // It works fine
I used the below one as mentioned. But it's not working.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.10.2.min.js"><\/script>')</script>
Links I have referred
Detect that the Internet connection is offline?
Check Internet connectivity with jquery
and a few more.
Any suggestions?