Check for Jquery internet connection

Asked

Viewed 3,624 times

4

Does anyone know a good function or a good way to check if there is an internet connection before making an ajax request?

1 answer

6


It’s possible, try to:

var online = navigator.onLine; // true ou false, (há, não há conexão à internet)
if(online) {
    // efetuar pedido ajax
}

To test, create a file on your computer, e.g., online.html and type:

<script>
    var online = navigator.onLine;
    alert(online);
</script>

Open it in the browser and turn the connection off/on to test

Browser other questions tagged

You are not signed in. Login or sign up in order to post.